tag:blogger.com,1999:blog-18838471191276157582024-03-12T19:23:48.859-07:00Java's Chronicleget to know about Java!!Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-1883847119127615758.post-35488238621018654452014-12-02T02:03:00.004-08:002014-12-02T02:03:42.783-08:00Synchronizing files in Eclipse <div dir="ltr" style="text-align: left;" trbidi="on">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</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-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--><!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</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-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<br />
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b style="mso-bidi-font-weight: normal;">File Synchronization for JSP :</b></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
While
developing web applications, we frequently change JSP contents, but in order to
reflect those changes we often copy the file into .WAR folder deployed on the
server. Though it is small steps as we are used to, but how good it will be if
we have changes reflecting automatically….doesn’t it sounds pretty cool???</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Here
we go…</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
There
is a plugin called FileSync for eclipse IDE.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Here
are the steps to enable:</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Step1:
Download the following JAR from the location: <a href="http://andrei.gmxhome.de/filesync/links.html" target="_blank">http://andrei.gmxhome.de/filesync/links.html</a>
</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Download
which ever the version is suitable for your eclipse.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
(Or,
if you have Eclipse Marketplace [<i>Help</i> > <i>Eclipse Marketplace...</i>
in Eclipse Indigo and above], use this URL: <a href="http://marketplace.eclipse.org/content/filesync" target="_blank">http://marketplace.eclipse.org/content/filesync</a>)<br style="mso-special-character: line-break;" />
<br style="mso-special-character: line-break;" />
</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
2.
Place this JAR in <b>eclipse/dropins</b> directory and restart eclipse.<br />
<br />
3. In Project Explorer, right click the project which has the JSP files and
choose <b>Properties</b>.<br />
<br />
4. In the <b>Properties</b> window, select "<b>File synchronization</b>"
on the left.<br />
<br />
5. Select the checkbox <b>"[] Enable FileSync builder for project</b>".<br />
<br />
6. Click on "<b>Add Folder</b>" button and select the folder which is
the root folder of all JSP files (for eg, you may select
Project/j2ee-apps/XXX/Module.war folder).<br />
<br />
7. Click on "<b>Browse...</b>" button against "Default target
folder" and choose the WAR folder inside your deployed EAR folder in the
app server (for eg, in Jboss, it would be <br />
C:\jboss-eap-5.1\jboss-as\server\{server-configuration}\deploy\{Project}.ear\{module}.war).<br />
<br />
8. Click <b>OK</b>.<br />
<br />
9.FileSync plugin does an initial synchronization. Test it by making small
changes to JSP , and see the changes reflected.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
This
reduces lots of time while developing.</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Enjoy
coding…..</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Thanks
,</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
Shyamala</div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
</div>
Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-73216297824736932572012-09-21T07:35:00.001-07:002012-09-21T07:35:41.295-07:00Java Comparable vs Comparator interface <div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Let us see the basic interfaces and its
methods: </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">public interface java.lang.Comparable{</span></div>
<div class="MsoNormal">
<span lang="EN-IN"> public
abstract int compareTo(java.lang.Object);</span></div>
<div class="MsoNormal">
<span lang="EN-IN">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">public interface java.util.Comparator{</span></div>
<div class="MsoNormal">
<span lang="EN-IN"> public
abstract int compare(java.lang.Object, java.lang.Object);</span></div>
<div class="MsoNormal">
<span lang="EN-IN"> public
abstract boolean equals(java.lang.Object);</span></div>
<div class="MsoNormal">
<span lang="EN-IN">}</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Let us observe the following code :</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> Here
i am trying to sort some group of stirng objects using Arrays.sort() method and
collections.sort() method respectively it sorted and gave me the proper output
....but when i tried to sort group of employee objects i got the exception as :</span><span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">Exception in thread "main" </span><u><span lang="EN-IN" style="color: navy; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">java.lang.ClassCastException</span></u><span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">: Employee cannot be cast to java.lang.Comparable<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN"> java.util.ArrayList;<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN"> java.util.Arrays;<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN"> java.util.Collections;<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN"> java.util.List;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">class</span></b><span lang="EN-IN"> Test {<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">static</span></b><span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">void</span></b><span lang="EN-IN"> main(String[] args) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> String
names []={</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Apple"</span><span lang="EN-IN">,</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Avacado"</span><span lang="EN-IN">,</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Apricot"</span><span lang="EN-IN">,</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Grapes"</span><span lang="EN-IN">,</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Gooseberries"</span><span lang="EN-IN">};<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> Arrays.<i>sort</i>(names);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> System.</span><i><span lang="EN-IN" style="color: #0000c0; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN">.println(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Using Arrays.sort()"</span><span lang="EN-IN">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN"> (String lString
: names) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> System.</span><i><span lang="EN-IN" style="color: #0000c0; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN">.println(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Fruit :"</span><span lang="EN-IN">+lString);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> List<string>
fruits = </string></span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> ArrayList<string>();<o:p></o:p></string></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN"> (String lString
: names) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> fruits.add(lString);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> Collections.<i>sort</i>(fruits);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> System.</span><i><span lang="EN-IN" style="color: #0000c0; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN">.println(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Using Collections.sort()"</span><span lang="EN-IN">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN"> (String lString
: fruits) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> System.</span><i><span lang="EN-IN" style="color: #0000c0; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN">.println(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Fruit :"</span><span lang="EN-IN">+lString);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> Employee
emp[] = </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee[5];<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> emp[0]
= </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"R001"</span><span lang="EN-IN">, </span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Robin"</span><span lang="EN-IN">, 45000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> emp[1]
= </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"R012"</span><span lang="EN-IN">, </span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Antony"</span><span lang="EN-IN">, 55000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> emp[2]
= </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"R011"</span><span lang="EN-IN">, </span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Williams"</span><span lang="EN-IN">, 75000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> emp[3]
= </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"R121"</span><span lang="EN-IN">, </span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"John"</span><span lang="EN-IN">, 65000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> emp[4]
= </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"R061"</span><span lang="EN-IN">, </span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"James"</span><span lang="EN-IN">, 35000);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> Arrays.<i>sort</i>(emp);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> </span><b><span lang="EN-IN" style="color: #7f0055; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN">(Employee e:emp){<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> System.</span><i><span lang="EN-IN" style="color: #0000c0; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN">.println(</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"Employee :id :"</span><span lang="EN-IN">+e.getEmpId()+</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">" \t Name
:"</span><span lang="EN-IN">+e.getEmpName()+</span><span lang="EN-IN" style="color: #2a00ff; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">"\t sal :"</span><span lang="EN-IN">+e.getEmpSal());<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">Output: <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Using Arrays.sort()<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Apple<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Apricot<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Avacado<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Gooseberries<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Grapes<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Using Collections.sort()<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Apple<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Apricot<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Avacado<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Gooseberries<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Fruit :Grapes<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">Exception in thread "main" </span><u><span lang="EN-IN" style="color: navy; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">java.lang.ClassCastException</span></u><span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">: Employee cannot be cast to java.lang.Comparable<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";"> at
java.util.Arrays.mergeSort(Unknown Source)<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";"> at
java.util.Arrays.sort(Unknown Source)<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";"> at Test.main(</span><u><span lang="EN-IN" style="color: navy; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">Test.java:40</span></u><span lang="EN-IN" style="color: red; mso-bidi-font-family: "Courier New"; mso-fareast-font-family: "Courier New";">)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">When trying to sort Employee objects the error because
Arrays.sort()<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">See the method :<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> public static void
sort(java.lang.Object[]);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> All elements in the
array must implement the<b><i> Comparable interface.</i></b>Then only it can do
natural ordering of elements.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">So i changed my Employee class as below : <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> java.util.Comparator;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">class</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">implements</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">
Comparable<employee> {<o:p></o:p></employee></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">private</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> String </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpId</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">private</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> String </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpName</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">private</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">double</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpSal</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(String pEmpId, String pEmpName, </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">double</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> pEmpSal) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">super</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">();<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpId</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpId;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpName</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpName;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpSal</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpSal;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> String getEmpId() {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpId</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">void</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> setEmpId(String pEmpId) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpId</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpId;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> String getEmpName() {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpName</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">void</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> setEmpName(String pEmpName) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpName</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpName;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">double</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> getEmpSal() {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpSal</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">void</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> setEmpSal(</span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">double</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">
pEmpSal) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpSal</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = pEmpSal;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #646464; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">@Override<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">int</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> compareTo(Employee empObj) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">double</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empSal = empObj.getEmpSal();<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empSal > </span><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">mEmpSal</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> ? 0 : 1;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">/*<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";"> * This is to compare based on empName<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";"> */<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">static</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Comparator<employee> </employee></span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">EmployeeNameComparator</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Comparator<employee>() {<o:p></o:p></employee></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #646464; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">@Override<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">int</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> compare(Employee e1, Employee e2) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> e1.getEmpName().compareTo(e2.getEmpName());</span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">/*<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";"> * This is to compare based on employee id<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="color: #3f7f5f; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";"> */<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">static</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Comparator<employee> </employee></span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">EmployeeIdComparator</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Comparator<employee>() {<o:p></o:p></employee></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="color: #646464; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">@Override<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">int</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> compare(Employee e1, Employee e2) {<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">return</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> e1.getEmpId().compareTo(e2.getEmpId());<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Here with this class you can observe i have implemented method <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> public abstract int
compareTo(java.lang.Object);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> This method will
automatically have current object and then gets the next object to compare.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">This method i have overriden to sort employee based on their
salary.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Now coming to<i><u> <b>Comparator</b></u></i><b> </b>interface you
can observe<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"> public abstract int compare(java.lang.Object,
java.lang.Object);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> It takes two arguments
obj1,obj2.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">When ever you want to add any other sorting techniques for your
custom objects you can use this.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Here in my class i have created two anonymous classes to sort
employee objects based on their name and employeeId.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">import</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> java.util.Arrays;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">class</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> EmpMain {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">public</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">static</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">void</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> main(String[] args) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee
emp[] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee[5];<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> emp[0] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"R001"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, </span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Robin"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, 45000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> emp[1] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"R012"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, </span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Antony"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, 55000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> emp[2] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"R011"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, </span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Williams"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, 75000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> emp[3] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"R121"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, </span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"John"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, 65000);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> emp[4] = </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Employee(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"R061"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, </span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"James"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">, 35000);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Arrays.<i>sort</i>(emp);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.println(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Without
any comparator : "</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">(Employee e:emp){<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.println(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Employee
:id :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpId()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">" \t Name :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpName()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"\t
sal :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpSal());<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> Arrays.<i>sort</i>(emp,Employee.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">EmployeeIdComparator</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.println(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"With
empId comparator : "</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">(Employee e:emp){<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.</span><u><span lang="EN-IN" style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">println</span></u><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">(</span><span lang="EN-IN" style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"Employee
:id :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpId()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">" \t Name :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpName()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: 'Courier New'; font-size: 10pt;">"\t
sal :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+e.getEmpSal());</span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Without any comparator : <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R061 Name :James
sal :35000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R001 Name :Robin
sal :45000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R012 Name :Antony
sal :55000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R121 Name :John
sal :65000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R011 Name :Williams
sal :75000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">With empId comparator : <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R001 Name :Robin
sal :45000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R011 Name :Williams
sal :75000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R012 Name :Antony
sal :55000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R061 Name :James
sal :35000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Employee :id :R121 Name :John
sal :65000.0<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">This also u can use :<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">List <employee> empList = </employee></span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">new</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">
ArrayList<employee>();<o:p></o:p></employee></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empList.add(emp[0]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empList.add(emp[1]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empList.add(emp[2]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empList.add(emp[3]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> empList.add(emp[4]);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <b><i>Collections.sort(empList);<o:p></o:p></i></b></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> (Employee lEmployee : empList) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.println(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Employee
:id :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpId()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">" \t Name :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpName()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"\t sal :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpSal());<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">Collections.sort(empList,Employee.</span></i></b><b><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">EmployeeNameComparator</span></i></b><b><i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">);<o:p></o:p></span></i></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span lang="EN-IN" style="color: #7f0055; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">for</span></b><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> (Employee lEmployee : empList) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> System.</span><i><span lang="EN-IN" style="color: #0000c0; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">out</span></i><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">.println(</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"Employee
:id :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpId()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">" \t Name :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpName()+</span><span lang="EN-IN" style="color: #2a00ff; font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Courier New";">"\t sal :"</span><span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;">+lEmployee.getEmpSal());<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Conclusion :<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Use Comparable for natural sort ordering and use Comparator for
any custom sorting .....<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN">Always Arrays.sort() and Collections.sort() can sort only objects
of type comparable.<o:p></o:p></span></div>
</div>
Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-91210332461600006862010-06-22T07:47:00.000-07:002010-06-22T07:47:03.301-07:00Eclipse key board shortcuts -Techies<strong>Eclipse key board shortcuts :</strong><br />
<br />
<br />
<strong>Ctrl+space. Autocomplete.</strong><br />
This will recommend a list of classes they will fit what you have typed so far. If there is only one match, it will just print it out for you. After it does print it out for you, it will include the import for you. If something is ever missing the import at the top, I will just go to the Class declaration and just hit Ctrl+space.<br />
<br />
<strong>Ctrl+Shift+O : Import packages:</strong><br />
This is very much required when we have to import packages for classes. (Organizing)<br />
<br />
<strong>Ctrl+Shift+R. Open resource.</strong><br />
I cannot live without this shortcut. It is such a time saver. Whenever you are trying to find a specific class, just start typing it and it will populate which classes match that criteria. Once you found it, select it and there you go! It also works great if you are new to a framework and need to find certain classes or if you partly recall the class name but not 100% sure.<br />
<br />
<strong>Ctrl+O. Show inherited members.</strong><br />
This is another one that works great when you are working with classes with a massive lump of methods attached to it. You COULD do this within the Package Explorer, but no one likes touching that mouse! You can even type to filter down your methods. If you have methods with the same name and just different parameters, this also works great. Just type in part of the method name and get a few overview and access to each of the methods.<br />
<br />
<strong>Ctrl+H. Loads search box.</strong><br />
I cant tell you how often this saves me. This isnt just a ‘find’ box, this does a ‘find in files’ within the File Search tab. Within here, you can specify what you are looking for in the files, what you file types you want to search in, etc. There are other types of search you can use, but I have not run into a case where I need them. Have you?<br />
<br />
<strong>Ctrl+Shift+C. Comments a block of code.</strong><br />
This is perfect for debugging. It is strange because really when you think about it, you are only talking about having something put a /* at the begging of what you selected and a */ at the end of what you selected. However, I use this a lot more often than you would expect.<br />
<br />
<strong>Ctrl+D. Delete a line.</strong><br />
Self explanatory. Extremely useful. If I didn’t have that, I’d have to waste time with Shift+End, Delete!.<br />
<br />
<strong>Ctrl+E. Menu for opened files.</strong><br />
This will bring up a list of opened files that you have. Not only that, it will also allow you to type in your class names to narrow down your choices.<br />
<br />
<strong>Ctrl+Shift+E : Window for Opened files:</strong><br />
This key is used to view all the files opened in the editor , where it will be easy to identify & open the files .<br />
<br />
<strong>Ctrl+1: </strong><br />
Is used for renaming variables at a time through out the file. Will be useful when we want to rename the variable name where the variable being used at many places.<br />
<br />
<strong>F4. Shows class hierarchy.</strong><br />
This is extremely useful when you are new to a with a massive framework and you really want to get a sense of how things are all connect, who extends what, etc.<br />
<br />
<strong>F3 and Ctrl+Left Mouse Click. Shows declaration.</strong><br />
I enjoy using this when I am working with larger files or anything with long methods (which always irks me). It can get extremely annoying to see where some variables are declared. All you have to do is high light the variable then hit F3. Sometimes I will hold control and hover over variable names if I am having a problem.<br />
<br />
<strong>F5, F6, F7, F8. In debug mode.</strong><br />
There three shortcuts are probably used more than anything. I wanted to group them all into one section.<br />
<br />
<strong>F5 – Step Into. </strong>When you are debugging an application and you come across a function call, F5 will step into that function and proceed from there.<br />
<br />
<strong>F6 – Step.</strong> This allow you to debug line by line. However, this will not step into any functions.<br />
<br />
<strong>F7 – Step out.</strong> If you are debugging in a function and you want to step out of it to where the function was called, this is what is used.<br />
<br />
<strong>F8 – Skip to next breakpoint</strong>. If there arent any other break points to high, you will be just running the application until your application hits another breakpoint, taking you back into debug mode.<br />
<br />
<strong>Alt+leftarrow or Alt+rightarrow.</strong> Jump back to a line, Jump forward to a line.<br />
According to eclipse, this is “Next word, Previous word’. I am not sure what that means. All I know if I am stepping into functions, debugging through multiple files and breakpoints, this is a life saver. It allows me to retrace my steps, step by step. If I go back with Alt+leftarrow, I can go right back to where I was with Alt+rightarray.<br />
<br />
<strong>Ctrl+Shift+L.</strong> Displays all shortcuts.<br />
Self explanitory. Dig in and find your favorite!This last one is not about using a shortcut. It is about what you have to do to turn it of. <br />
<br />
<strong>Ctrl+W or Ctrl+F4:</strong> close the single file.<br />
This is used to close the current file that is opened in the editor.<br />
<br />
<strong>Ctrl+Shift+W or Ctrl+Shift+F4 </strong>: Close all the files:<br />
When many files we have opened this is very much useful to close all the files opened in the editor in a single shot.<br />
<br />
<strong>Alt + left key : </strong>Navigation<br />
This is used to navigate from one page to another page in the left direction .<br />
<br />
<strong>Alt+right key :</strong> the same as above for right navigation.<br />
<br />
<strong>Ctrl+Shift+/ </strong>: comment<br />
This is used to add the block level comment in a page.<br />
<br />
<strong>Ctrl+Shift+\ : remove comment</strong><br />
<br />
<strong>Ctrl+Shift+F : Formatting contents</strong><br />
<br />
Save your time using keyboard....... <br />
<br />
Rocking, <br />
ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-4611024114221380732010-06-19T07:51:00.000-07:002010-06-19T07:51:18.253-07:00ECLIPSE DEBUGGING TUTORIALDebugging Using eclipse :<br />
<br />
Let us consider one simple Java project :<br />
<br />
Where i have created in the following manner.<br />
<div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_3UvVh-40xf0/TBzQH_xohbI/AAAAAAAACj8/yb-5Q3VHpTQ/s1600/s.bmp" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" qu="true" src="http://2.bp.blogspot.com/_3UvVh-40xf0/TBzQH_xohbI/AAAAAAAACj8/yb-5Q3VHpTQ/s320/s.bmp" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Presently it is in java perspective.......<br />
<br />
we can change the perspective into debugging by clicking WINDOW-->Open perspective ---> and go<br />
<br />
to other and select “Debug”.<br />
<br />
Then : <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_3UvVh-40xf0/TBzSYvHELyI/AAAAAAAACkE/cK4GYBlJlKw/s1600/s1.bmp" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="172" qu="true" src="http://1.bp.blogspot.com/_3UvVh-40xf0/TBzSYvHELyI/AAAAAAAACkE/cK4GYBlJlKw/s320/s1.bmp" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
We can add the break point lines by double clicking on the line in source code...<br />
<br />
<ul><li>You can observe clearly there are areas EXECUTION STACK,WATCH VARIABLES AND EXPRESSION AREA,SOURCE CODE Area,and as well CONSOLE SCREEN.</li>
</ul><br />
<strong><em>Observe the following screen shot to add watch expression as well as execution environmen</em>t</strong><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_3UvVh-40xf0/TBzTvdPlLHI/AAAAAAAACkM/T5zfXFfU9pU/s1600/s3.bmp" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" qu="true" src="http://1.bp.blogspot.com/_3UvVh-40xf0/TBzTvdPlLHI/AAAAAAAACkM/T5zfXFfU9pU/s320/s3.bmp" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<ul><li> By using F11 key we can start debugging any Java application.</li>
</ul> Here in this case i have added two watch expression one is “i” value and another is “str1” value.<br />
<br />
<ul><li> By using F6 key we can do step by step execution of a program.</li>
</ul><br />
<ul><li>By using F8 key we can skip the current break point it will be jumping into the next break point start.</li>
</ul><br />
<strong>Observe the next screen shot which shows the values of “i” & str1</strong><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_3UvVh-40xf0/TBzVqYg0WiI/AAAAAAAACkU/z9TAYkUqVRs/s1600/s4.bmp" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" qu="true" src="http://4.bp.blogspot.com/_3UvVh-40xf0/TBzVqYg0WiI/AAAAAAAACkU/z9TAYkUqVRs/s320/s4.bmp" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Thats it ..............<br />
<br />
This is simple debugging of Java application.<br />
<br />
JUST SCROLL DOWN........<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_3UvVh-40xf0/TBzWrXlX_-I/AAAAAAAACkc/8crRNSU7gcU/s1600/s5.bmp" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="185" qu="true" src="http://3.bp.blogspot.com/_3UvVh-40xf0/TBzWrXlX_-I/AAAAAAAACkc/8crRNSU7gcU/s320/s5.bmp" width="320" /></a></div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
This is how it will be after termination of Program...which stops with THREAD....<br />
<br />
Very much required as a developer to know how to use Eclipse debugging ......as in the real world applications development no body will prefer using System.out.println();......<br />
<br />
<br />
So be the best by learning & practicing this .....<br />
<br />
Keep Rocking <br />
ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-32785652674037415332010-04-13T22:05:00.000-07:002010-04-13T22:12:31.115-07:00Displaying IP Address of the system using RuntimeRuntime is a class which is specifically made for the purpose to run any kind of process using "exec" method<br /><br />import java.io.*;<br />class DisplayIP{<br /> public static void main(String args[]){<br /><br /> Runtime runtime = Runtime.getRuntime(); <br /> try{<br /> Process process = runtime.exec(<span style="font-weight:bold;">"cmd.exe /c ipconfig"</span>);<br /> InputStream in = process.getInputStream();<br /> int ch = in.read();<br /> while(ch!=-1){<br /> System.out.print((char)ch);<br /> ch=in.read();<br /> }<br /> in.close();<br /> }<br /> catch(IOException e){<br /> System.out.println(e);<br /> }<br /> }<br />}<br /><br />Still any doubt !!! check out by clicking the link<br />http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html<br />Cheers<br />ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-61187202736126763392010-04-13T00:14:00.000-07:002010-04-13T00:27:51.538-07:00Deep Copy vs Shallow Copy in C++Usually in c++ we will be more confused about these constructors about deep copying & shallow copying.....<br /><br />Here is a simple example where there is a class called String where we have to strings which is used to store firstname ,lastname and the age of the person.<br /><br />Where in case of this I am creating the Object of String with the name s1 which after reading the details I am assigning it to one more Object s2.<br /><br /><br /><br />#include<iostream.h><br />#include<string.h><br />#include<conio.h><br /><br />class String<br />{<br /> char *firstname; // declaring pointer to store string<br /> char *lastname;<br /> int age;<br /><br /> public:<br /> String()<br /> {<br /> firstname = new char[30];<br /> lastname = new char[30];<br /> age=0;<br /> }<br /> void read()<br /> {<br /> cout<<"\n Enter name:";<br /> cin>>firstname>>lastname;<br /> cout<<"\n age :";<br /> cin>>age;<br /> }<br /> void print()<br /> {<br /> cout<<"\n name is "<<firstname<<" "<<lastname;<br /> cout<<"\n Age :"<<age;<br /> }<br /> ~String()<br /> {<br /> delete[]firstname;<br /> delete[]lastname;<br /> }<br />};<br /><br />void main()<br />{<br /> clrscr();<br /><br /> String s1;<br /> s1.read();<br /> s1.print();<br /><br /> String s2=s1; //assigning the object s1 to s2 <br /> s2.print();<br /><br /> s1.read();<br /><br /> s1.print();<br /> s2.print();<br /><br /> getch();<br />}<br /><br />U can observe after u make any changes to the s1 object with the Strings that is firstname,lastname it will be reflected in s2 object also.<br /><br />So by default there is one copy constructor given for you in your c++ classes which will be of this prototype which just assigns the values using "=" operator.<br /><br />Prototype of Copy constructor:<br /> ClassName(ClassName &Object){<br /> }<br />This is <span style="font-weight:bold;">"SHALLOW COPYING"</span><br />For the above class :<br /> String(String &s){<br /> firstname=s.firstname;<br /> lastname=s.lastname;<br /> age = s.age;<br /> }<br /><br />To over come this problem where it should be allocated with the own memory allocations just keep this below code and observe which is called <span style="font-weight:bold;">"DEEP COPYING"</span><br /><br /> String(String &s)<br /> {<br /> cout<<"\n copying......";<br /> int l1= strlen(s.firstname)+1;<br /> int l2= strlen(s.lastname)+1;<br /> firstname = new char[l1];<br /> lastname = new char[l2];<br /> strcpy(firstname,s.firstname);<br /> strcpy(lastname,s.lastname);<br /> age=s.age;<br /> }<br /><br /><br />SHALLOW COPYING IS DEFAULT DONE .......WHICH OVERLOADS "=" operators.<br /><br />DEEP COPYING YOU SHOULD WRITE ON YOUR OWN!!<br /><br />Cheers<br />ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-42717323757625433282010-04-10T04:40:00.000-07:002010-04-10T04:41:26.726-07:00SCJP QuestionsQuestion 1 :<br />class Demo{<br /> public static void main(String args){<br /> System.out.println("welcome to java");<br /> }<br />}<br /><br />What will be the output of the program:<br />a) Error at compile time b) Error at Runtime<br />c) prints welcome to java d) No Error and no output<br /><br />===============================================================<br />Question 2:<br />Which of the following are legal statements in Java?<br />a) float f=1/3; b) float f=1.01;<br />c) int i=1/3; d) double d=999d;<br /><br />===============================================================<br />Question 3:<br />What will happen when you compile and run the following code?<br />public class MyClass{ <br /> static int i; <br /> public static void main(String argv[]){ <br /> System.out.println(i); <br /> } <br />} <br />a) Error Variable i may not have been initialized c) 1<br />b) null d) 0 <br /><br />===============================================================<br />Question 4:<br />class Demo{<br /> static void print(){<br /> System.out.println("Hello");<br /> }<br /> public static void main(String args){<br /> Demo d =null;<br /> d.print();<br /> }<br />}<br /><br />a) Error at compile time b) Error at Runtime <br />c) prints Hello d) No Error and no output<br /><br />===============================================================Question 5:<br />Which of the following statements are true?<br />a) A byte can represent between -128 to 127 <br />b) A byte can represent between -256 to 256<br />c) A byte can represent between -127 to 128 <br />d) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1<br /><br />===============================================================Question 6:<br />Which of the following statements are true?<br />a) Constructors cannot have a visibility modifier <br />b) Constructors can only have a primitive return type<br />c) Constructors can be marked public and protected, but not private <br />d) Constructors are not inherited<br /><br />===============================================================Question 7:<br />What will happen when you attempt to compile and run the following class? <br />class Base{ <br />Base(int i){ <br /> System.out.println("Base"); <br /> } <br />} <br />class Severn extends Base{ <br />public static void main(String argv[]){ <br /> Severn s = new Severn(); <br /> } <br />void Severn(){ <br /> System.out.println("Severn"); <br /> } <br />} <br />a) Compilation and output of the string "Severn" at runtime <br />b) Compilation and no output at runtime<br />c) Compile time error<br />d) Compilation and output of the string "Base"<br /><br />===============================================================Question 8:<br />Given the following code<br />class Base {} <br /> <br />class Agg extends Base{ <br /> public String getFields(){ <br /> String name = "Agg"; <br /> return name; <br /> } <br />} <br />public class Avf{ <br />public static void main(String argv[]){ <br /> Base a = new Agg(); <br /> //Here <br /> } <br />} <br />What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"? <br />a) System.out.println(a.getFields()); <br />b) System.out.println((Base) a.getFields());<br />c) System.out.println(a.name); <br />d) System.out.println( ((Agg) a).getFields());<br /><br />===============================================================Question 9:<br />What will happen when you attempt to compile and run the following code? <br />public class Inc{ <br />public static void main(String argv[]){ <br /> Inc inc = new Inc(); <br /> int i =0; <br /> inc.fermin(i); <br /> i = i++; <br /> System.out.println(i); <br /> } <br /> void fermin(int i){ <br /> i++; <br /> } <br />} <br />a) Compile time error b) Output of 1<br />c) Output of 2 d) Output of 0<br /> <br />===============================================================Question 10:<br />Given the following class <br />public class Ombersley{ <br />public static void main(String argv[]){ <br /> boolean b1 = true; <br /> if((b1 ==true) || place(true)){ <br /> System.out.println("Hello Crowle"); <br /> } <br /> } <br /> <br /> public static boolean place(boolean location){ <br /> if(location==true){ <br /> System.out.println("Borcetshire"); <br /> } <br /> System.out.println("Powick"); <br /> return true; <br /> } <br />} <br />What will happen when you attempt to compile and run it?<br />a) Compile time error <br />b) Output of Borcetshire and Powick followed by "Hello Crowle"<br />c) Output of "Hello Crowle" <br />d) No output<br />===============================================================Question 11:<br />What will happen when you attempt to compile and run the following code? <br />public class Sandys{ <br />private int court; <br />public static void main(String argv[]){ <br /> Sandys s = new Sandys(99); <br /> System.out.println(s.court); <br /> } <br />Sandys(int ballcount){ <br /> court=ballcount; <br /> } <br />} <br />a) Compile time error, the variable court is defined as private<br />b) Compile time error, s is not initialized when the System.out method is called <br />c) Compilation and execution with no output<br />d) Compilation and run with an output of 99<br />===============================================================<br />Question 12:<br />Given the following code <br />class Base{ <br />static int oak=99; <br />} <br />public class Doverdale extends Base{ <br />public static void main(String argv[]){ <br /> Doverdale d = new Doverdale(); <br /> d.amethod(); <br /> } <br /> public void amethod(){ <br /> //Here <br /> } <br />} <br />Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak? <br />a) super.oak=1; b) Base.oak=22;<br />c) oak=33; d) oak=50.1;<br />===============================================================Question 13:<br />Which of the following statements are true?<br />a) A method cannot be overloaded to be less public in a child class<br />b) To be overridden a method only needs the same name and parameter types<br />c) To be overridden a method must have the same name, parameter and return types<br />d) An overridden method must have the same name, parameter names and parameter types<br />===============================================================Question 14:<br />You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?<br /><br />a)myarray.length();<br />b)myarray.length;<br />c)myarray.size<br />d)myarray.size();<br />===============================================================Question 15:<br />What will happen when you attempt to compile and run this program<br />public class Outer{<br />public String name = "Outer";<br />public static void main(String argv[]){<br /> Inner i = new Inner();<br /> i.showName();<br /> }//End of main<br /> private class Inner{<br /> String name =new String("Inner");<br /> void showName(){<br /> System.out.println(name);<br /> }<br /> }//End of Inner class<br />}<br />a) Compile and run with output of "Outer"<br />b) Compile and run with output of "Inner"<br />c) Compile time error because Inner is declared as private<br />d) Compile time error because of the line creating the instance of Inner<br />===============================================================Question 16:<br />Given the following class definition, which of the following methods could be legally placed after the comment //Here<br /><br />public class Rid{<br /> public void amethod(int i, String s){}<br /> //Here<br />}<br />a)public void amethod(String s, int i){}<br />b)public int amethod(int i, String s){}<br />c)public void amethod(int i, String mystring){}<br />d) public void Amethod(int i, String s) {}<br />===============================================================Question 17:<br />public class Test7{<br /> public Test7(){}<br /> public Test7(Test7 ref){<br /> this (ref,"Hai");<br /> }<br /> public Test7(Test7 ref,String str){ <br /> ref.Test7(str);<br /> System.out.println("Hi");<br /> }<br /> public void Test7(String str){<br /> System.out.println(str);<br /> }<br /> public static void main(String[] args){<br /> Test7 t = new Test7();<br /> Test7 t7 = new Test7(t); <br /> }<br /> }<br />a) HI b) hai<br />c) Hai Hi d) Hi Hai<br />===============================================================Question 18:<br />What will be the output of the following program?<br /><br />class Sup1{<br /> public Sup1(){<br /> System.out.println("Hai");<br /> }<br /> private Sup1(String str){<br /> System.out.println(str);<br /> }<br />}<br /><br />public class Test5 extends Sup1{<br /> private Test5(String str){<br /> System.out.println(str);<br /> super();<br /> }<br /> public static void main(String[] args) {<br /> Test5 t5 = new Test5("HI");<br /> }<br />}<br /> <br />a) Hai,Hi,Hi b) Hai,Hi<br />c) Hi,Hi d) Compiler Error<br />===============================================================Question 19:<br />class VarArgOne {<br /> public static void printArgs(String s, int ... i, String s) { //line1<br /> for(int j : i) { //line 2<br /> System.out.print(j + " " + s); //line 3<br /> } <br /> }<br /> public static void main(String ... args) { //line 4<br /> printArgs("exam", 12, 34, "scjp"); //line 5<br /> }<br />}<br />a) Compilation fails due to error at line 1.<br />b) Compilation fails due to error at line 2.<br />c) Compilation fails due to error at line 4.<br />d) Compilation fails due to error at both line 1 and line 4.<br />e) Compiles fine and Prints output "12 scjp 34 scjp".<br />===============================================================Question 20:<br />class A{ <br /> private void print(){<br /> System.out.println("===print in A===");<br /> }<br />}<br />class B extends A{<br /> void print(){<br /> System.out.println("===print in B===");<br /> }<br />}<br />class M{<br /> public static void main(String args[]){<br /> A ref = new B();<br /> ref.print();<br /> }<br />}<br />What happens when we try to compile the above program:<br />a)Error at compile time b)Error at run time<br />c)prints print in A d) prints print in B <br />===============================================================Question 21 :<br />interface I{<br /> void print();<br />}<br />class A{ <br /> static void print(){<br /> System.out.println("===print in A===");<br /> }<br />}<br />class B extends A implements I{<br /> public void print(){<br /> System.out.println("===print in A===");<br /> }<br />}<br />class M{<br /> public static void main(String args[]){<br /> A ref = new B();<br /> ref.print();<br /> }<br />}<br />What will be the output & Write explanation?<br />===============================================================Question 22:<br />What all gets printed when the following code is compiled and run? Select the three correct answers.<br />public class xyz {<br /> public static void main(String args[]) {<br /> for(int i = 0; i < 2; i++) {<br /> for(int j = 2; j>= 0; j--) {<br /> if(i == j) break;<br /> System.out.println("i=" + i + " j="+j);<br /> }<br /> }<br /> }<br />}<br />===============================================================Question 23:<br />What is the result of compiling and running the following program. Select the one correct answer.<br />class test {<br /> public static void main(String args[]) {<br /> int[] arr = {1,2,3,4};<br /> call_array(arr[0], arr);<br /> System.out.println(arr[0] + "," + arr[1]); <br /> }<br /> static void call_array(int i, int arr[]) {<br /> arr[i] = 6;<br /> i = 5;<br /> } <br />}<br /> a. 1,2 b. 5,2<br /> c. 1,6 d. 5,6<br />===============================================================Question 24:<br />Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer.<br /> a. test();<br /> b. super.test();<br /> c. super.super.test();<br /> d. ::test();<br /> e. C.test();<br /> f. It is not possible to invoke test() method defined in C from a method in A.<br />===============================================================Question 25:<br />Which of the following are legal array declarations. Select the three correct answers.<br /> a. int i[5][]; b. int i[][];<br /> c. int []i[]; d. int i[5][5];<br /> e. int[][] a;<br />===============================================================<br /> ALL THE BESTShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-41375879912281212472010-04-10T04:34:00.000-07:002010-04-10T04:39:14.726-07:00Difference Between String VS StringBuffer VS StringBuilderShown below is an example that concatanates 10000 strings using the '+' operator, StringBuffer, and StringBuilder, and prints the operation time in <strong>nanoseconds</strong>. The ability to get time in nanoseconds is another feature that was added in JDK 1.5.<br /><br /><code><span style="color: rgb(127, 0, 85);"><strong>public class </strong></span><span style="color: rgb(0, 0, 0);">StringConcatanations </span><span style="color: rgb(0, 0, 0);">{</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static final </strong></span><span style="color: rgb(127, 0, 85);"><strong>int </strong></span><span style="color: rgb(0, 0, 0);">MAX_ITER = </span><span style="color: rgb(153, 0, 0);">10000</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static </strong></span><span style="color: rgb(127, 0, 85);"><strong>void </strong></span><span style="color: rgb(0, 0, 0);">main</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">String</span><span style="color: rgb(0, 0, 0);">[] </span><span style="color: rgb(0, 0, 0);">args</span><span style="color: rgb(0, 0, 0);">) {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">concatenate</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">concatenateWithStringBuffer</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">concatenateWithStringBuilder</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static </strong></span><span style="color: rgb(127, 0, 85);"><strong>void </strong></span><span style="color: rgb(0, 0, 0);">concatenate</span><span style="color: rgb(0, 0, 0);">() {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Concatanating using the + operator"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">String s1 = </span><span style="color: rgb(42, 0, 255);">""</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">s1Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>for</strong></span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85);"><strong>int </strong></span><span style="color: rgb(0, 0, 0);">i=</span><span style="color: rgb(153, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i<max_iter;i++></max_iter;i++></span><span style="color: rgb(0, 0, 0);">) {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">s1 = s1 + </span><span style="color: rgb(42, 0, 255);">"abc"</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">e1Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Time: " </span><span style="color: rgb(0, 0, 0);">+ </span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">e1Time - s1Time</span><span style="color: rgb(0, 0, 0);">))</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static </strong></span><span style="color: rgb(127, 0, 85);"><strong>void </strong></span><span style="color: rgb(0, 0, 0);">concatenateWithStringBuffer</span><span style="color: rgb(0, 0, 0);">() {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Concatanating using StringBuffer"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">StringBuffer sb = </span><span style="color: rgb(127, 0, 85);"><strong>new </strong></span><span style="color: rgb(0, 0, 0);">StringBuffer</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">s2Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>for</strong></span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85);"><strong>int </strong></span><span style="color: rgb(0, 0, 0);">i=</span><span style="color: rgb(153, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i<max_iter;i++></max_iter;i++></span><span style="color: rgb(0, 0, 0);">) {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">sb.append</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"abc"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">e2Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Time: " </span><span style="color: rgb(0, 0, 0);">+ </span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">e2Time - s2Time</span><span style="color: rgb(0, 0, 0);">))</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static </strong></span><span style="color: rgb(127, 0, 85);"><strong>void </strong></span><span style="color: rgb(0, 0, 0);">concatenateWithStringBuilder</span><span style="color: rgb(0, 0, 0);">() {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Concatanating using StringBuilder"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">StringBuilder sBuilder = </span><span style="color: rgb(127, 0, 85);"><strong>new </strong></span><span style="color: rgb(0, 0, 0);">StringBuilder</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">s3Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>for</strong></span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85);"><strong>int </strong></span><span style="color: rgb(0, 0, 0);">i=</span><span style="color: rgb(153, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i<max_iter;i++></max_iter;i++></span><span style="color: rgb(0, 0, 0);">) {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">sBuilder.append</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"abc"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">e3Time = getNanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">System.out.println</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(42, 0, 255);">"Time: " </span><span style="color: rgb(0, 0, 0);">+ </span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">e3Time - s3Time</span><span style="color: rgb(0, 0, 0);">))</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><span style="color: rgb(255, 255, 255);"> </span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>public static </strong></span><span style="color: rgb(127, 0, 85);"><strong>long </strong></span><span style="color: rgb(0, 0, 0);">getNanoTime</span><span style="color: rgb(0, 0, 0);">() {</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(127, 0, 85);"><strong>return </strong></span><span style="color: rgb(0, 0, 0);">System.nanoTime</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">;</span><br /><span style="color: rgb(255, 255, 255);"> </span><span style="color: rgb(0, 0, 0);">}</span><br /><br /><span style="color: rgb(0, 0, 0);">}</span></code> <!--<br /> end source code --> <p><br />Output:<br />Concatanating using the + operator<br />Time: 744597428<br />Concatanating using StringBuffer<br />Time: 1685131<br />Concatanating using StringBuilder<br />Time: 1317206</p><p><br /></p><p>Check out the time taken to append the String using "+" operator!!</p><p>As you can see, if you do not need thread safety, StringBuilder yeilds the best result, followed by Stringuffer, followed by the '+' operator. However, if you do need thread safety, then StringBuffer is your natural choice.</p><p>Cheers</p><p>Shyamala<br /><strong></strong></p><div style="text-align: left;" class="java" align="left"><br /></div>Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com1tag:blogger.com,1999:blog-1883847119127615758.post-3351892957347061472010-03-15T00:55:00.000-07:002010-03-15T00:59:54.073-07:00EL functions in JSP<span style="font-weight: bold;">EL Functions:</span><br />Very simple used to invoke any functions with names.......<br /><br />For Ex:<br /><br /><span style="font-weight: bold;">create a class as below:com.fun.Message</span><br /><br />package com.fun;<br />/*<br />* A class Which contains the user defined funcion sayHello<br />*/<br />public class Message{<br /><br /> public static String sayHello(){<br /><br /> return "hello!!";<br /> }<br />}<br /><br />Keep this .class under /WEB-INF/classes/com/fun/Message.class<br /><br /><br /><span style="font-weight: bold;">Then we have to create TLD file which describes your functions :</span><br /><span style="font-weight: bold;">myfucntions.tld:</span><br /><br /><taglib><br /> <tlib-version>1.0</tlib-version><br /> <jsp-version>1.1</jsp-version><br /><br /> <function><br /> <name>hello</name><br /> <function-class>com.fun.Message</function-class><br /> <function-signature>java.lang.String sayHello()</function-signature><br /> </function><br /><br /> <function><br /> <name>rand</name><br /> <function-class>java.lang.Math</function-class><br /> <function-signature>long random()</function-signature><br /> </function><br /><br /> <function><br /> <name>absolute</name><br /> <function-class>java.lang.Math</function-class><br /> <function-signature>int abs(int)</function-signature><br /> </function><br /><br /></taglib><br /><br />You can observer this TLD is describing some predefined functions of java.lang.Math class also.<br /><br />Save this file as " myfunctions.tld" keep this under /WEB-INF folder of your application.<br /><br />"name" tag in function is necessary with that name only user is going to call the functions.<br /><br /><span style="font-weight: bold; font-style: italic;">Then at last create your jsp</span>:<br /><br /><%@page isELIgnored="false" %><br /><%@taglib uri="/WEB-INF/myfunctions.tld" prefix="f" %><br /><br />${f:hello()}<br />${f:rand()}<br />${f:abso lute(10)}<br /><br /><br />Rocking<br />ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-40353494362201427552010-03-09T22:42:00.000-08:002010-03-09T22:58:35.535-08:00Difference between @include & jsp:includeTo get to know the difference between these two<br /><br /><%@include file="" %> is a directive<br /><br />Action tag:<br /><br /><jsp:include page="{relativeURL | <%= expression %>}" flush="true" /><br />or<br /><jsp:include page="{relativeURL | <%= expression %>}" flush="true" ><br /><br /> <jsp:param name="parameterName"<br /><br /> value="{parameterValue | <%= expression %>}" /><br /><br /></jsp:include><br /><br /><br /><br />one.jsp<br />=========<br /><br /><%@page isELIgnored="false"%><br /><br /><jsp:declaration>int cnt=0;</jsp:declaration><br /><jsp:expression>"Shyamala"+cnt++</jsp:expression><br /><jsp:include page="two.jsp"/><br /><br />two.jsp<br />==========<br />I am just included<br /><br />now go to work directory of tomcat and check out there will be two seperate servlets created<br /><br />and even u can observe one line in one_jsp.java file<br />org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "two.jsp", out, false);<br /><br />which specifies the page is included at run time<br /><br />just change your one.jsp file as following<br /><br />one.jsp<br /><br /><%@page isELIgnored="false"%><br /><br /><br /><jsp:declaration>int cnt=0;</jsp:declaration><br /><jsp:expression>"Shyamala"+cnt++</jsp:expression><br /><%@ include file="two.jsp"%><br /><br />you will not be created with two different java files in work directory the two.jsp contents also will be included in the same one_jsp.java file.<br /><br />That means it is done at the time of compilation!!<br /><br /><br />Rocking !!<br />ShyamalaShyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-74717150878045442552010-02-20T02:09:00.000-08:002010-02-20T02:34:56.258-08:00Calendar of a month using Javaimport java.util.*;<br />/*<br />* Printing the calendar of a month where the user<br />* Gives the input month , year<br />* By Shyamala<br />*/<br />class CalendarForMonth{<br />public static void main(String args[]){<br />//A string array for months<br /><br />String months []={"Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"};<br /><br />//An integer for number of days in every month<br />int nDays[]={31,28,31,30,31,30,31,31,30,31,30,31};<br /><br />//creating the instance of calendar<br />Calendar calendar = Calendar.getInstance();<br /><br />Scanner in = new Scanner(System.in);<br />//Take the input from the user Month,Year<br /><br />System.out.print("Enter month ,year :");<br />int mon = in.nextInt(); int yr = in.nextInt();<br />calendar.set(yr,mon-1,1); //setting date yr,mon,date consider first day<br /><br />if(yr%4==0){<br />System.out.println("Leap year!!");<br />//change the number of days Feb month as it is leap year<br />nDays[1]=29;<br />}<br /><br />System.out.println("Calendar For "+calendar.get(Calendar.YEAR)+" == "+months[calendar.get(Calendar.MONTH)]);<br /><br />//printing the days<br />System.out.print("S\tM\tTu\tW\tTh\tF\tSa");<br />int day = calendar.get(Calendar.DAY_OF_WEEK);<br />//System.out.println(day);<br />System.out.println();<br /><br />//gives you the starting day<br />int nline=0;<br />//for getting new lines<br /><br />for(int i=1;i<=nDays[mon-1];i++){<br />System.out.print(i+"\t");<br />nline++;<br />if(nline%7==0)<br />System.out.println("\n");<br />}<br /><br />}<br /><br />}Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-52676250907479080462010-01-18T05:23:00.000-08:002010-01-18T05:40:01.279-08:00String vs StringBuffer vs StringBuilder<strong><span style="color:#009900;">Difference between String , StringBuffer and StringBuilder :</span><br /></strong><br /><br />Let us first write one sample program using Java String:<br /><br />Program:<br /><br />class Demo{<br />public static void main(String args[]){<br />String s ="shyamala";<br />System.out.println("java"+s);<br />}<br />}<br /><br /><br />compile the above program and run u get the output as : javashyamala<br />then after this see the description about the bytecode using<br /><br />cmd/> javap -c Demo<br /><br />Compiled from "Demo.java"<br />class Demo extends java.lang.Object{<br />Demo();<br />Code:<br />0: aload_0<br />1: invokespecial #1; //Method java/lang/Object."<init>":()V<br />4: return<br />public static void main(java.lang.String[]);<br />Code:<br />0: ldc #2; //String shyamala<br />2: astore_1<br />3: getstatic #3; //Field java/lang/System.out:Ljava/io/PrintStream;<br /><strong>6: new #4; //class java/lang/StringBuilder</strong><br />9: dup<br />10: invokespecial #5; //Method java/lang/StringBuilder."<init>":()V<br />13: ldc #6; //String java<br /><strong>15: invokevirtual #7; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;<br /></strong>18: aload_1<br /><strong>19: invokevirtual #7; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder;<br /></strong>22: invokevirtual #8; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;<br />25: invokevirtual #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V<br />28: return<br />}<br /><br />observe the highlighted lines in the above bytecode where by inbuilt it is using StringBuilder class when it is creating string.When we are using "+" operator with the strings it invokes append method of stringBuilder.<br /><br />GC will be invoked manier times in case of String as once the string literal is not used again it should invoke Garbagecollector.<br /><br /><br />Other options include with javap:<br /><br />javap -c Demo<br />to print Java1 Virtual Machine bytecodes,<br /><br />javap -l Demo<br />to display line number and local variable tables (you need to compile perf.java with -g for this to work), and<br /><br />javap -p Demo<br />to print private methods and fields in addition to the public ones.<br />javap is a handy tool for digging beneath the surface to find out what's really going on in a .class file.<br /><br /><br />About string :<br />1)Immutable class<br />2) Not thread safe<br /><br />the performance is higher as it is using StringBuilder but when it is required frequent appending to a string better to go for stringBuffer which is mutable as well thread safety class.<br /><br />StringBuilder<br />1) Mutable<br />2)Not threadsafety<br /><br />StringBuffer:<br />1)Mutable<br />2)Threadsafety<br /><br /><a href="http://java.sun.com/developer/TechTips/1998/tt0120.html#tip1">http://java.sun.com/developer/TechTips/1998/tt0120.html#tip1</a><br />Thats it any queries get back to me!!!Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-74168736316598708362009-06-12T22:17:00.000-07:002009-06-12T22:33:58.582-07:00Digital Clock Using "C"This is Very simple<br /><br /> there is an header file called "dos.h" which contains predefined structures for time and date.<br /> So i have declared here two variables of type<br /><br /> struct date d;<br /> struct time t;<br /><br /><br />to get the current system date and time call function getdate() & gettime() where these functions take date , time respectively.<br /><br /> getdate(&d);<br /> gettime(&t);<br /><br /><span style="font-weight: bold; font-style: italic;">PredefinedStructures :</span><br /><span style="font-weight: bold;">date:</span><br />struct date { <br /><br />int da_year; /* current year */ <br />char da_day; /* day of the month */<br />char da_mon; /* month (1 = Jan) */<br /><br />};<br /><br /><span style="font-weight: bold;">time:</span><br />struct time { <br />unsigned char ti_min; /* minutes */ <br />unsigned char ti_hour; /* hours */ <br />unsigned char ti_hund; /* hundredths of seconds */<br />unsigned char ti_sec; /* seconds */<br />};<br /><br />-------------------------------------------------------------------------------------------<br /><div style="text-align: center;"> <span style="font-weight: bold; font-style: italic;">Program : Digital clock</span><br /></div>-------------------------------------------------------------------------------------------<br />#include<conio.h>"stdio.h"<br />#include"dos.h"<br />#include"conio.h"<br /><dos.h><br />void main()<br />{<br /> struct date d;<br /> struct time t;<br /> clrscr();<br /><br /> do{<br /> getdate(&d);<br /> gettime(&t);<br /><br /> gotoxy(15,11);<br /> textcolor(YELLOW);<br /> cprintf("***************************************");<br /> gotoxy(15,13);<br /> cprintf(" Digital Clock using C ");<br /> gotoxy(15,15);<br /> cprintf("***************************************");<br /> textcolor(WHITE);<br /> gotoxy(35,17);<br /> cprintf(" by shyamala ");<br /> gotoxy(15,19);<br /> textcolor(YELLOW);<br /> cprintf("***************************************");<br /><br /> textcolor(WHITE);<br /><br /> gotoxy(23,24);<br /> cprintf("Date(dd/mm/yy) : %d/%d/%d",d.da_day,d.da_mon,d.da_year);<br /> gotoxy(23,26);<br /> cprintf("Time(hr/min/sec) : %d/%d/%d",t.ti_hour,t.ti_min,t.ti_sec);<br /><br /> gotoxy(27,30);<br /><br /> textcolor(RED);<br /> cprintf("Dear User Hit Any key to Exit!!");<br /><br /> delay(100);<br /> }<br /> while(!kbhit());<br />}<br /><br /><br />------------------------------------------------------------------------------------------------<br /></dos.h></conio.h><div style="text-align: center;"><conio.h><dos.h><span style="font-weight: bold; font-style: italic;">Ouput :</span></dos.h></conio.h><br /><conio.h><dos.h></dos.h></conio.h></div><conio.h><dos.h>------------------------------------------------------------------------------------------------<br /><br /></dos.h></conio.h><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_3UvVh-40xf0/SjM5L77fl-I/AAAAAAAACK4/oeDQB2ocuLI/s1600-h/op.bmp"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 196px;" src="http://4.bp.blogspot.com/_3UvVh-40xf0/SjM5L77fl-I/AAAAAAAACK4/oeDQB2ocuLI/s320/op.bmp" alt="" id="BLOGGER_PHOTO_ID_5346680059847481314" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><span style="font-weight: bold; font-style: italic;">Keep rocking</span><br /><span style="font-weight: bold; font-style: italic;">Shyamala</span>Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-41092532880439296292009-06-09T21:36:00.000-07:002009-06-09T21:37:27.523-07:00100 windows keyboard shortcuts list<p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><b><i style=""><u><span style="font-size: 15.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows key board shortcuts<o:p></o:p></span></u></i></b></p> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 15.5pt; line-height: 150%; font-family: "Times New Roman","serif";">The General Shortcuts<o:p></o:p></span></u></i></b></p> <p class="MsoListParagraph" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">We’ll kickoff the list with some really general shortcuts that you often used.<o:p></o:p></span></p> <ol start="1" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+C (Copy)<o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+X (Cut)<o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+V (Paste) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+Z (Undo) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">DELETE (Delete) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL while dragging an item (Copy the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+SHIFT while dragging an item (Create a shortcut to the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">selected</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F2 key (Rename the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+DOWN ARROW (Move the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">insertion</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> point to the beginning of the next paragraph) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+SHIFT with any of the arrow keys (Highlight a block of text) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+A (Select all) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F3 key (Search for a file or a folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+ENTER (View the properties for the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+F4 (Close the active item, or quit the active program) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+ENTER (Display the properties of the selected object) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+SPACEBAR (Open the shortcut menu for the active window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+TAB (Switch between the open items) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+ESC (Cycle through items in the order that they had been opened) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F6 key (Cycle through the screen elements in a window or on the desktop) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F4 key (Display the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">Address bar</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> list in My Computer or Windows Explorer) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT+F10 (Display the shortcut menu for the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+SPACEBAR (Display the System menu for the active window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+ESC (Display the Start menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+Underlined letter in a menu name (Display the corresponding menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Underlined letter in a command name on an open menu (Perform the corresponding command) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F10 key (Activate the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">menu bar</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> in the active program) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">RIGHT ARROW (Open the next menu to the right, or open a submenu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">LEFT ARROW (Open the next menu to the left, or close a submenu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F5 key (Update the active window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">BACKSPACE (View the folder one level up in My Computer or Windows Explorer) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ESC (Cancel the current task) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Dialog Box Keyboard Shortcuts<o:p></o:p></span></u></i></b></p> <ol start="39" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+TAB (Move forward through the tabs) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+SHIFT+TAB (Move backward through the tabs) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">TAB (Move forward through the options) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT+TAB (Move backward through the options) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+Underlined letter (Perform the corresponding command or select the corresponding option) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ENTER (Perform the command for the active option or button) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SPACEBAR (Select or clear the check box if the active option is a check box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Arrow keys (Select a button if the active option is a group of option buttons) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F1 key (Display Help) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F4 key (Display the items in the active list) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Microsoft Natural Keyboard Shortcuts</span></u></i></b><b style=""><i style=""><u><span style="font-size: 13pt; line-height: 150%; font-family: "Times New Roman","serif";"><o:p></o:p></span></u></i></b></p> <ol start="50" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo (Display or hide the Start menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+BREAK (Display the System Properties dialog box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+D (Display the desktop) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+M (Minimize all of the windows) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+SHIFT+M (Restore the minimized windows) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+E (Open My Computer) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+F (Search for a file or a folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+Windows Logo+F (Search for computers) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+F1 (Display Windows Help) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+ L (Lock the keyboard) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+R (Open the Run </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">dialog box</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo+U (Open Utility Manager)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 15.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Accessibility Keyboard Shortcuts<o:p></o:p></span></u></i></b></p> <ol start="62" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Right SHIFT for eight seconds (Switch FilterKeys either on or off) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">five times</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> (Switch the StickyKeys either on or off) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">NUM LOCK for five seconds (Switch the ToggleKeys either on or off) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Logo +U (Open Utility Manager) <o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Windows Explorer Keyboard Shortcuts<o:p></o:p></span></u></i></b></p> <ol start="68" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">END (Display the bottom of the active window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">HOME (Display the top of the active window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">NUM LOCK+Plus sign (+) (Display the contents of the selected folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">NUM LOCK+Minus sign (-) (Collapse the selected folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Shortcut Keys for Character Map<o:p></o:p></span></u></i></b></p> <ol start="75" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts: <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">RIGHT ARROW (Move to the right or to the beginning of the next line) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">LEFT ARROW (Move to the left or to the end of the previous line) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">UP ARROW (Move up one row) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">DOWN ARROW (Move down one row) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">PAGE UP (Move up one screen at a time) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">PAGE DOWN (Move down one screen at a time) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">HOME (Move to the beginning of the line) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">END (Move to the end of the line) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+HOME (Move to the first character) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+END (Move to the last character) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SPACEBAR (Switch between Enlarged and Nor mal mode when a character is selected)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Microsoft Management Console (MMC) Main Window Keyboard Shortcuts<o:p></o:p></span></u></i></b></p> <ol start="87" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+O (Open a saved console) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+N (Open a new console) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+S (Save the open console) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+M (Add or remove a console item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+W (Open a new window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F5 key (Update the content of all console windows) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+SPACEBAR (Display the MMC window menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+F4 (Close the console) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+A (Display the Action menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+V (Display the View menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+F (Display the File menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+O (Display the Favorites menu) <o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 14.5pt; line-height: 150%; font-family: "Times New Roman","serif";">MMC Console Window Keyboard Shortcuts<o:p></o:p></span></u></i></b></p> <ol start="99" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+P (Print the current page or active pane) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+Minus sign (-) (Display the window menu for the active console window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">SHIFT+F10 (Display the Action shortcut menu for the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F1 key (Open the Help topic, if any, for the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F5 key (Update the content of all console windows) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+F10 (Maximize the active console window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+F5 (Restore the active console window) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+ENTER (Display the Properties dialog box, if any, for the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">F2 key (Rename the selected item) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 15.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Remote Desktop Connection Navigation<o:p></o:p></span></u></i></b></p> <ol start="109" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+ALT+END (Open the micro$oft Windows </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">NT Security</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> dialog box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+PAGE UP (Switch between programs from left to right) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+PAGE DOWN (Switch between programs from right to left) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+INSERT (Cycle through the programs in most recently used order) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+HOME (Display the Start menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+ALT+BREAK (Switch the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">client</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> computer between a window and a full screen) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">ALT+DELETE (Display the Windows menu) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the </span><u><span style="font-size: 9pt; line-height: 150%; font-family: "Times New Roman","serif"; color: rgb(34, 119, 221);">Terminal server</span></u><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"> clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+ALT+Plus sign (+) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="text-align: justify; line-height: 150%;"><b><i style=""><u><span style="font-size: 15.5pt; line-height: 150%; font-family: "Times New Roman","serif";">Internet Explorer navigation<o:p></o:p></span></u></i></b></p> <ol start="118" type="1"><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+B (Open the Organize Favorites dialog box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+E (Open the Search bar) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+F (Start the Find utility) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+H (Open the History bar) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+I (Open the Favorites bar) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+L (Open the Open dialog box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+N (Start another instance of the browser with the same Web address) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+O (Open the Open dialog box, the same as CTRL+L) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+P (Open the Print dialog box) <o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+R (Update the current Web page)<o:p></o:p></span></li><li class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";">CTRL+W (Close the current window)<o:p></o:p></span></li></ol> <p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; line-height: 150%;"><span style="font-size: 12pt; line-height: 150%; font-family: "Times New Roman","serif";"><o:p> </o:p></span></p> <p class="MsoNormal" style="text-align: justify; line-height: 150%; font-weight: bold; font-style: italic;"><span style="font-family: "Times New Roman","serif";"><o:p> Keep Rocking</o:p></span></p><p class="MsoNormal" style="text-align: justify; line-height: 150%;"><span style="font-family: "Times New Roman","serif";"><o:p><span style="font-weight: bold; font-style: italic;">Shyamala</span><br /></o:p></span></p>Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-10567097718236176472009-06-08T01:37:00.000-07:002009-06-08T01:51:40.003-07:00JVM-Java Virtual Machine<p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><b style=""><u><span style="line-height: 150%;font-size:16;" >JVM- Java Virtual Machine<o:p></o:p></span></u></b></p> <p style="line-height: 150%;"><span style="line-height: 150%;font-size:18;" >A</span>t the heart of the Java platform lies the Java Virtual Machine, or JVM. Most programming languages compile source code directly into machine code, suitable for execution on a particular microprocessor architecture. The difference with Java is that it uses bytecode - a special type of machine code. </p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;">The designers of Java chose to use a combination of compilation and interpretation. Programs written in Java are compiled into machine language, but it is a machine language for a computer that doesn't really exist. This so-called "virtual" computer is known as the </span><span class="newword"><b style="">Java virtual machine</b></span><span style="color:black;">. The machine language for the Java virtual machine is called </span><span class="newword"><b style="">Java bytecode</b></span><span style="color:black;">. There is no reason why Java bytecode could not be used as the machine language of a real computer, rather than a virtual computer.<o:p></o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;"><o:p> </o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;"><o:p> </o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_3UvVh-40xf0/SizO7WbfMBI/AAAAAAAACKM/VQr8f2PfTeQ/s1600-h/s.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 330px; height: 127px;" src="http://3.bp.blogspot.com/_3UvVh-40xf0/SizO7WbfMBI/AAAAAAAACKM/VQr8f2PfTeQ/s320/s.jpg" alt="" id="BLOGGER_PHOTO_ID_5344874376810410002" border="0" /></a>A program written in Java could certainly be compiled into the machine language of a real computer. And programs written in other languages could be compiled into Java bytecode. However, it is the combination of Java and Java bytecode that is platform-independent, secure, and network-compatible while allowing you to program in a modern high-level object-oriented language.<o:p></o:p></p><div><span style="color:black;"></span><p></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;"><o:p> </o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;"><o:p> </o:p></span></p> <p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><b style=""><span style="line-height: 150%;font-size:14;color:black;" >“Java is WORA Write Once Run Anywhere”<o:p></o:p></span></b></p> <p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><b style=""><span style="line-height: 150%;font-size:14;color:black;" ><o:p> </o:p></span></b></p> <p class="MsoNormal" style="text-align: center;" align="center"><b style=""><span style=";font-size:14;color:blue;" >The Architecture of the Java Virtual Machine<o:p></o:p></span></b></p> <p class="MsoNormal" style="text-align: center;" align="center"><b style=""><span style=";font-size:14;color:blue;" ><o:p> </o:p></span></b></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;">The behavior of a virtual machine instance is described in terms of subsystems, memory areas, data types, and instructions. These components describe an abstract inner architecture for the abstract Java virtual machine. <o:p></o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><!--[if gte vml 1]><v:shape id="_x0000_s1026" type="#_x0000_t75" alt="" style="'position:absolute;margin-left:3.4pt;" wrapcoords="-110 -122 -110 21661 21710 21661 21710 -122 -110 -122" bordertopcolor="blue" borderleftcolor="blue" borderbottomcolor="blue" borderrightcolor="blue" filled="t" fillcolor="#36f" stroked="t" strokecolor="blue" strokeweight="1.5pt"> <v:imagedata src="file:///C:\DOCUME~1\shyamala\LOCALS~1\Temp\8\msohtmlclip1\01\clip_image003.png" href="http://www.artima.com/insidejvm/ed2/images/fig5-1.gif"> <w:wrap type="square"> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--><span style="color:black;"><br /></span></p><p class="MsoNormal" style="line-height: 150%;"><span style="color:black;">Figure shows a block diagram of the Java virtual machine that includes the major subsystems and memory areas. <o:p></o:p></span></p> <p class="MsoNormal" style="text-align: center; line-height: 150%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_3UvVh-40xf0/SizPs-mK8VI/AAAAAAAACKU/Rl_QNJ5wN3U/s1600-h/aa.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_3UvVh-40xf0/SizPs-mK8VI/AAAAAAAACKU/Rl_QNJ5wN3U/s320/aa.jpg" alt="" id="BLOGGER_PHOTO_ID_5344875229406228818" border="0" /></a></p><p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><span style="color:black;"><br /></span></p><p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><span style="color:black;">Figure The internal architecture of the Java virtual machine.</span><span style="color:black;"><o:p></o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;">Each Java virtual machine has<o:p></o:p></span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in; line-height: 150%;"><!--[if !supportLists]--><span style=";font-family:Wingdings;color:black;" ><span style="">ü<span style=""> </span></span></span><!--[endif]--><i style=""><span style="color:red;">a <span style="">class loader subsystem</span></span></i><span style="color:red;">:</span><span style="color:black;"> a mechanism for loading types (classes and interfaces) given fully qualified names. <o:p></o:p></span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in; line-height: 150%;"><!--[if !supportLists]--><span style=";font-family:Wingdings;color:black;" ><span style="">ü<span style=""> </span></span></span><!--[endif]--><span style="color:black;">Java virtual machine organizes the memory it needs to execute a program into several </span><i><span style="color:red;">runtime data areas</span></i><span style="color:red;">.</span><span style="color:black;"><o:p></o:p></span></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in; line-height: 150%;"><!--[if !supportLists]--><span style=";font-family:Wingdings;color:black;" ><span style="">ü<span style=""> </span></span></span><!--[endif]--><i style=""><span style="color:red;">an <span style="">execution engine</span>:</span></i><span style="color:black;"> a mechanism responsible for executing the instructions contained in the methods of loaded classes. <o:p></o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><span style="color:black;">Each instance of the Java virtual machine has one <span style="">method area</span> and one <span style="">heap</span>. These areas are shared by all threads running inside the virtual machine. As the program runs, the virtual machine places all objects the program instantiates onto the heap.<o:p></o:p></span></p> <p class="MsoNormal" style="line-height: 150%;"><b style=""><span style="line-height: 150%;font-size:14;color:black;" ><span style=""> </span></span></b><b style=""><span style="line-height: 150%; color: rgb(0, 102, 255);font-size:14;" ><span style=""> </span>“Bytecode is independent , JVM is dependent.”<o:p></o:p></span></b></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal"><i style=""><span style=""><o:p> </o:p></span></i></p> <p class="MsoNormal" style="text-align: center; line-height: 150%;" align="center"><b style=""><span style="line-height: 150%;font-size:14;color:black;" ><o:p> </o:p></span></b></p></div>Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0tag:blogger.com,1999:blog-1883847119127615758.post-68281705615416678592009-06-05T21:43:00.000-07:002009-06-05T22:07:02.964-07:00Creating Jar file (Java executables) - Very simple<span style="font-size:130%;"><span style="font-family:lucida grande;"><span style="font-weight: bold; font-style: italic;">Step 1: </span><br /><span style="font-weight: bold; font-style: italic;"> Create a Hello.java class .</span><br /> public class Hello{<br /> public static void main(String args[]){<br /> System.out.println("welcome to Java’s chronicle");<br /> }<br /> } <br /><br /><span style="font-weight: bold; font-style: italic;">Step-2 :</span><br /> <span style="font-weight: bold; font-style: italic;">Compile the above java file. </span><br /><br /> Cmd > javac Hello.java<br /><br /><span style="font-weight: bold; font-style: italic;">Step- 3:</span><br /><span style="font-weight: bold; font-style: italic;"> Create a mainClass.txt with the following contents</span><br /><br /> Main-Class: Hello<br /><br />Note :<br /></span></span><span style="font-size:130%;">Remember the above must be terminated with carriage return coz some of the OS expects CR to create Manifest file.<br /><br /></span><span style="font-size:130%;"><span style="font-weight: bold; font-style: italic;font-family:lucida grande;" >Step- 4:<br /></span><span style="font-family:lucida grande;"><span style="font-weight: bold; font-style: italic;"> Go to command prompt create jar file<br /><br /></span></span><span style="font-family:lucida grande;"> Cmd > jar -cvmf mainClass.txt my1.jar Hello.class</span><br /><span style="font-family:lucida grande;"> success :</span><br /><span style="font-family:lucida grande;"> added manifest</span><br /><span style="font-family:lucida grande;"> adding: Hello.class(in = 411) (out= 282)(deflated 31%)</span><br /><br /><span style="font-family:lucida grande;"> where :</span><span style="font-family:lucida grande;"><br /> c-create jar</span><br /><span style="font-family:lucida grande;"> v-verbose</span><br /><span style="font-family:lucida grande;"> m-mainclassfile<br /><br /></span></span><span style="font-size:130%;"><span style="font-family:lucida grande;"><span style="font-weight: bold; font-style: italic;">Step 5:</span><br /><span style="font-weight: bold; font-style: italic;">To list the contents of jar</span><br /><br />Cmd > jar tf my1.jar<br /><br /> META-INF/<br /> META-INF/MANIFEST.MF<br /> Hello.class<br /><br /><span style="font-weight: bold; font-style: italic;">Step 6:</span><br /><span style="font-weight: bold; font-style: italic;"> To Execute jar </span><br /><br /> Cmd > java –jar my1.jar<br /><br />I just tried explaining in a layman terminology ...Hope it is useful<br />Further any queries kindly get back to me......<br /><br />Keep Rocking<br />Shyamala<br /><br /></span></span>Shyamala Vydyamhttp://www.blogger.com/profile/15088445441937635752noreply@blogger.com0