<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7008884275520011766</id><updated>2012-02-07T10:28:54.685-08:00</updated><category term='DTD'/><category term='Microsoft Visio'/><category term='enum'/><category term='GWT'/><category term='Conditional Statement'/><category term='package'/><category term='sub-package'/><category term='Loop'/><category term='Dialog'/><category term='Event Listener'/><category term='PriorityQueue'/><category term='UML'/><category term='XML'/><category term='Comparator'/><category term='&quot;No source code is available for the type ...&quot; Error'/><category term='Sort'/><category term='Java'/><category term='Static'/><category term='Variable'/><category term='JDBC'/><category term='ClassNotFoundException'/><category term='subpackage'/><category term='Tomcat'/><category term='Unicode'/><category term='I/O'/><category term='File'/><category term='Array'/><category term='Graphics'/><category term='Database'/><category term='Console'/><category term='Singleton'/><category term='Eclipse'/><category term='Iterator'/><category term='Processing'/><category term='For-Each'/><category term='SAXException'/><category term='Applet'/><category term='ClassCastException'/><category term='Heap'/><title type='text'>Once Upon a Coding ...</title><subtitle type='html'>I'm here to share my programming adventures with other people. I do a lot with different programming languages and frameowkrs for implementation/validation of my research projects, fun and of course to make money! So the posts on this weblog represent what I find interesting during my work.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-5545770298213467199</id><published>2011-12-27T07:59:00.001-08:00</published><updated>2011-12-27T07:59:44.366-08:00</updated><title type='text'>Java and Beyond, a New Year Resolution ...</title><content type='html'>&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;o:OfficeDocumentSettings&gt;  &lt;o:RelyOnVML/&gt;  &lt;o:AllowPNG/&gt; &lt;/o:OfficeDocumentSettings&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;w:WordDocument&gt;  &lt;w:View&gt;Normal&lt;/w:View&gt;  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;  &lt;w:TrackMoves/&gt;  &lt;w:TrackFormatting/&gt;  &lt;w:PunctuationKerning/&gt;  &lt;w:ValidateAgainstSchemas/&gt;  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;  &lt;w:DoNotPromoteQF/&gt;  &lt;w:LidThemeOther&gt;EN-CA&lt;/w:LidThemeOther&gt;  &lt;w:LidThemeAsian&gt;X-NONE&lt;/w:LidThemeAsian&gt;  &lt;w:LidThemeComplexScript&gt;AR-SA&lt;/w:LidThemeComplexScript&gt;  &lt;w:Compatibility&gt;   &lt;w:BreakWrappedTables/&gt;   &lt;w:SnapToGridInCell/&gt;   &lt;w:WrapTextWithPunct/&gt;   &lt;w:UseAsianBreakRules/&gt;   &lt;w:DontGrowAutofit/&gt;   &lt;w:SplitPgBreakAndParaMark/&gt;   &lt;w:EnableOpenTypeKerning/&gt;   &lt;w:DontFlipMirrorIndents/&gt;   &lt;w:OverrideTableStyleHps/&gt;  &lt;/w:Compatibility&gt;  &lt;m:mathPr&gt;   &lt;m:mathFont m:val="Cambria Math"/&gt;   &lt;m:brkBin m:val="before"/&gt;   &lt;m:brkBinSub m:val="&amp;#45;-"/&gt;   &lt;m:smallFrac m:val="off"/&gt;   &lt;m:dispDef/&gt;   &lt;m:lMargin m:val="0"/&gt;   &lt;m:rMargin m:val="0"/&gt;   &lt;m:defJc m:val="centerGroup"/&gt;   &lt;m:wrapIndent m:val="1440"/&gt;   &lt;m:intLim m:val="subSup"/&gt;   &lt;m:naryLim m:val="undOvr"/&gt;  &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt; &lt;w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"  DefSemiHidden="true" DefQFormat="false" DefPriority="99"  LatentStyleCount="267"&gt;  &lt;w:LsdException Locked="false" Priority="0" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Normal"/&gt;  &lt;w:LsdException Locked="false" Priority="9" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/&gt;  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 1"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 2"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 3"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 4"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 5"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 6"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 7"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 8"/&gt;  &lt;w:LsdException Locked="false" Priority="39" Name="toc 9"/&gt;  &lt;w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/&gt;  &lt;w:LsdException Locked="false" Priority="10" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Title"/&gt;  &lt;w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/&gt;  &lt;w:LsdException Locked="false" Priority="11" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/&gt;  &lt;w:LsdException Locked="false" Priority="22" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Strong"/&gt;  &lt;w:LsdException Locked="false" Priority="20" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/&gt;  &lt;w:LsdException Locked="false" Priority="59" SemiHidden="false"   UnhideWhenUsed="false" Name="Table Grid"/&gt;  &lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/&gt;  &lt;w:LsdException Locked="false" Priority="1" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/&gt;  &lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/&gt;  &lt;w:LsdException Locked="false" Priority="34" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/&gt;  &lt;w:LsdException Locked="false" Priority="29" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Quote"/&gt;  &lt;w:LsdException Locked="false" Priority="30" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/&gt;  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Shading Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"   UnhideWhenUsed="false" Name="Light List Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"   UnhideWhenUsed="false" Name="Light Grid Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"   UnhideWhenUsed="false" Name="Dark List Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful List Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"   UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/&gt;  &lt;w:LsdException Locked="false" Priority="19" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/&gt;  &lt;w:LsdException Locked="false" Priority="21" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/&gt;  &lt;w:LsdException Locked="false" Priority="31" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/&gt;  &lt;w:LsdException Locked="false" Priority="32" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/&gt;  &lt;w:LsdException Locked="false" Priority="33" SemiHidden="false"   UnhideWhenUsed="false" QFormat="true" Name="Book Title"/&gt;  &lt;w:LsdException Locked="false" Priority="37" Name="Bibliography"/&gt;  &lt;w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/&gt; &lt;/w:LatentStyles&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt;&lt;style&gt; /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;}&lt;/style&gt;&lt;![endif]--&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Maybe this should be my NewYear resolution! I’m changing this blog from a just-java blog to my generalcoding experiment blog. First, I’m going to share a lot more especiallyregarding my Fall 2011 experience with C++. I’m also finding it more and moredifficult to tag every post with just one technology. When a simple chatapplication calls for PHP, JavaScript and Ajax, wouldn’t it be useless todivide a post on it in three different blogs? I guess I’m going to keep theaddress. After all, I’m still very Java-based and even a C++ programmer won’tmind a cup of Java once in a while.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-5545770298213467199?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/5545770298213467199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=5545770298213467199' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5545770298213467199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5545770298213467199'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/12/java-and-beyond-new-year-resolution.html' title='Java and Beyond, a New Year Resolution ...'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-4797088225466065944</id><published>2011-12-12T12:39:00.001-08:00</published><updated>2011-12-27T08:01:39.432-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft Visio'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='UML'/><title type='text'>Adding Java Data Types to Visio</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13pt; line-height: 115%;"&gt;If you want to create UMLdiagrams using Microsoft Visio but you cannot find Java data types in it, there’sa very quick way of getting them. As you know, Java data types are very similarto the ones of C# - or may I say C# is very similar to Java – You can duplicateC# data types and make any changes required later, e.g. I would change &lt;i&gt;string to String&lt;/i&gt; and &lt;i&gt;bool&lt;/i&gt; to &lt;i&gt;boolean&lt;/i&gt;. For this, assuming you’reusing Visio 2010, Go to UML menu, click on &lt;i&gt;Packages&lt;/i&gt;, select &lt;i&gt;C# Data Types&lt;/i&gt;and push &lt;i&gt;Duplicate&lt;/i&gt;. A new package will be added named &lt;i&gt;Package1&lt;/i&gt; orsomething like that. Change the name to something like &lt;i&gt;Java Data Types&lt;/i&gt;and click ok. You’re all set!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-4797088225466065944?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/4797088225466065944/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=4797088225466065944' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4797088225466065944'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4797088225466065944'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/12/adding-java-data-types-to-visio.html' title='Adding Java Data Types to Visio'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-7883609747450882282</id><published>2011-11-27T15:07:00.001-08:00</published><updated>2011-12-27T08:01:39.459-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Applet'/><category scheme='http://www.blogger.com/atom/ns#' term='Processing'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Graphics'/><title type='text'>Using Processing for simpler Graphics</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Creating animated graphicsand artworks is not easy in Java – ok, it’s a lot easier than C++ but still notclean – fortunately you can use &lt;i&gt;&lt;a href="http://processing.org/"&gt;Processing&lt;/a&gt;&lt;/i&gt;and export your code as a java jar file, applet or application, and hence useit in your java application. Processing takes care of many dirty details youhave to do manually in a regular java program. I’ve written a code to run asimple key catching game, which you can download from here. The game keepsgenerating random character and gives you a score every time you hit the rightcharacter. Simply download processing, copy &lt;a href="http://www.4shared.com/file/3fWKk4o0/KeyCatcher.html"&gt;my code&lt;/a&gt; – it comes with detailedcomments - and run the game. I know it’s not beautiful but it’s really easy tomake it look good, in terms of fonts and colors. You might also want to look atexamples from &lt;a href="http://catehuston.com/workshop/"&gt;this workshop&lt;/a&gt;, &lt;a href="http://www.catehuston.com/blog/"&gt;Cate Huston&lt;/a&gt; created and after helpingher a couple of times, I’ve continued teaching it. Once you save your projectand export it as an applet, go under the applet folder of your project and haveyour browser open the file &lt;i&gt;index.html&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-GuRAfD_EUXE/TtLDHXFfsrI/AAAAAAAAAWA/QVRxQ4236Ko/s1600/KeyCatcher.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-GuRAfD_EUXE/TtLDHXFfsrI/AAAAAAAAAWA/QVRxQ4236Ko/s320/KeyCatcher.jpg" width="288" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-7883609747450882282?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/7883609747450882282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=7883609747450882282' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7883609747450882282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7883609747450882282'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/11/using-processing-for-simpler-graphics.html' title='Using Processing for simpler Graphics'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-GuRAfD_EUXE/TtLDHXFfsrI/AAAAAAAAAWA/QVRxQ4236Ko/s72-c/KeyCatcher.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-354156243306810960</id><published>2011-10-13T15:15:00.000-07:00</published><updated>2011-12-27T08:01:39.420-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Static'/><title type='text'>An Example of using Static Members</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Static members, we all know,are class members that are shared amongst all instances of the class and thatyou can access them without instantiating the class – well, the compiler does adefault instantiation but that’s hidden from our point of view. Here’s a goodexample I just encountered today while programming a web application:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;I have a list of text labels– which I call them term buttons - that look like hyperlinks but they’re notreally. I wanted to change the color of every label when I click on it. Butwhen I click on another label, I want the previously clicked one to go back toits normal color (See the figure below). This way, User can always say whichlabel is being processed right now. So, I need to define a variable that alwaysholds the lastly clicked button but where to keep it? I have a controller forevery button and the GRASP patterns suggest that the controller is the bestplace to keep that because the controller is the one that needs it and will useit anyways.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: 17px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-QJ56oviNL_k/Tpdi4Hhpa6I/AAAAAAAAAVE/I4YOblNkAS4/s1600/Static+Example.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-QJ56oviNL_k/Tpdi4Hhpa6I/AAAAAAAAAVE/I4YOblNkAS4/s400/Static+Example.jpg" width="370" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: 17px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: 17px; line-height: 19px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;But how can I make sure thistracking variable has a consistent value and all instances of controller haveaccess to it? The answer is simply this, define it as a static member! This isthe code fragment of where I defined this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;TermSummaryController &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;implements&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; ClickHandler {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;private&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; TermButton &lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;selectedTermButton&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;It is null at the beginning andhere’s how I control it:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #646464; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;@Override&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;onClick(ClickEvent event) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TermButtontermButton=(TermButton)event.getSource();&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; (&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;selectedTermButton&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;!=&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;selectedTermButton&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;.setStyleName(&lt;/span&gt;&lt;span style="color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;"termButton"&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;);&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;selectedTermButton&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;=termButton;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;termButton.setStyleName(&lt;/span&gt;&lt;span style="color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;"termButtonClicked"&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;);&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;if &lt;i&gt;selectedTermButton&lt;/i&gt;is not null, which means a button has been clicked before, I simply set its styleback to normal. Then I assign the newly clicked button to &lt;i&gt;selectedTermButton&lt;/i&gt;and change its style to my clicked style.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;* &lt;/span&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;This code is written for Google WebToolkit and does not work with other Java-based frameworks but the idea remainsthe same.&lt;/span&gt;&lt;/i&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-354156243306810960?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/354156243306810960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=354156243306810960' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/354156243306810960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/354156243306810960'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/10/example-of-using-static-members.html' title='An Example of using Static Members'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-QJ56oviNL_k/Tpdi4Hhpa6I/AAAAAAAAAVE/I4YOblNkAS4/s72-c/Static+Example.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-4852622782810787891</id><published>2011-09-29T18:55:00.000-07:00</published><updated>2011-12-27T08:01:39.435-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Comparator'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='PriorityQueue'/><category scheme='http://www.blogger.com/atom/ns#' term='Heap'/><title type='text'>Max Heap using PriorityQueue</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Java has a niceimplementation of Heaps named PriorityQueue. Briefly, a heap is a tree datastructure, where the root is always either the minimum or maximum. The defaultin Java is minimum. Hence, if you need a maximum heap, you should somehowimplement your own comparator. For example the following comparator returns anumber greater than zero if the second parameter is bigger – unlike the naturalordering:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;import&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;java.util.Comparator;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; MyComparator &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;implements&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; Comparator&amp;lt;&lt;span style="background: silver; mso-highlight: silver;"&gt;Integer&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;{&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; compare( &lt;span style="background: silver; mso-highlight: silver;"&gt;Integer&lt;/span&gt; x, &lt;span style="background: silver; mso-highlight: silver;"&gt;Integer&lt;/span&gt; y )&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; y - x;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; line-height: 115%;"&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;A min heap on integers issimply defined as:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;PriorityQueue&lt;integer&gt;heap=&lt;/integer&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; PriorityQueue&lt;integer&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/integer&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Whereas a max heap onintegers, using MyComparator, is implemented as:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;PriorityQueue&lt;integer&gt;heap=&lt;/integer&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; PriorityQueue&lt;integer&gt;(n, &lt;/integer&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;MyComparator());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;n is the initial size of theheap.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-4852622782810787891?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/4852622782810787891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=4852622782810787891' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4852622782810787891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4852622782810787891'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/09/max-heap-using-priorityqueue.html' title='Max Heap using PriorityQueue'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-6136927629121528581</id><published>2011-09-22T06:29:00.001-07:00</published><updated>2011-12-27T08:01:39.448-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><category scheme='http://www.blogger.com/atom/ns#' term='Unicode'/><title type='text'>Declaring variables using Unicode</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;I just had this studentcoming to me this morning asking if identifier names have a lot of constraintsin Java? The answer is almost none – there are a few but compared to old daysis really nothing! The length is now unlimited – well virtually! – The name caninclude and start even with a dollar sign. And even more, you can have Unicode inyour variable names. &lt;span&gt;In the lattercase, you will need to use the compiler directive &lt;/span&gt;&lt;i&gt;–encoding&lt;/i&gt;&lt;span&gt; though, that isif you use UTF-8 in your code then your compile line will look like&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" class="MsoNormal" style="background: #F2F2F2; mso-background-themecolor: background1; mso-background-themeshade: 242; text-align: center;"&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;javac–encoding UTF-8 MyJavaProgram.java&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;In IDEs like Eclipse youmight face problems with just saving the file, so your main issue would just beto change the general encoding option. For example, in Eclipse, go to projectproperties and click on &lt;i&gt;Resource&lt;/i&gt;. Then change the &lt;i&gt;Text file encoding&lt;/i&gt;to whatever your desired encoding is.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-6136927629121528581?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/6136927629121528581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=6136927629121528581' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/6136927629121528581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/6136927629121528581'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/09/declaring-variables-using-unicode.html' title='Declaring variables using Unicode'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-166461826473277751</id><published>2011-09-18T18:55:00.001-07:00</published><updated>2011-12-27T08:01:39.397-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='ClassCastException'/><title type='text'>A more effective type checking approach ...</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;I said &lt;a href="http://once-upon-a-java.blogspot.com/search/label/ClassCastException"&gt;here&lt;/a&gt;that you can use &lt;i&gt;ClassCastException&lt;/i&gt; to identify the type of an object. Iwas correct but now I realized this isn’t very effective. It is much moreeffective to use a direct class comparison. So to find out if the type of anobject matches the desired class type simply use this check:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" class="MsoNormal" style="background: #F2F2F2; mso-background-themecolor: background1; mso-background-themeshade: 242; text-align: center;"&gt;&lt;i&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;anObject.getClass().equals(TheType.class)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-166461826473277751?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/166461826473277751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=166461826473277751' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/166461826473277751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/166461826473277751'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/09/more-effective-type-checking-approach.html' title='A more effective type checking approach ...'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-1960309052441888413</id><published>2011-09-15T15:38:00.001-07:00</published><updated>2011-12-27T08:01:39.404-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='ClassNotFoundException'/><title type='text'>ClassNotFoundException while running from command prompt</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Many Java beginners are advisedor tempted to try running Java from command prompt. As a beginner you mightset-up everything correctly and yet get the exception &lt;i&gt;ClassNotFoundException&lt;/i&gt;while running a successfully complied program. In some Windows versions youmight have this problem even if you &lt;i&gt;.class&lt;/i&gt; file exists within the samefolder. Simply try the following to remind JVM – and perhaps Windows! – that theclass file exists within the same directory – I’m assuming your java class isnamed &lt;i&gt;MyJavaProgram&lt;/i&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;java –classpath .MyJavaProgram&lt;/span&gt;&lt;/i&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;One more thing, if you haveto avoid IDEs for writing programs – Java or others – at least use &lt;a href="http://notepad-plus-plus.org/"&gt;Notepad++&lt;/a&gt;. It helps a lot, you’ll foryourself!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-1960309052441888413?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/1960309052441888413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=1960309052441888413' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/1960309052441888413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/1960309052441888413'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/09/classnotfoundexception-while-running.html' title='ClassNotFoundException while running from command prompt'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-2071636157040192963</id><published>2011-09-12T19:28:00.000-07:00</published><updated>2011-12-27T08:01:39.408-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Conditional Statement'/><title type='text'>less function calls wouldn't kill ...</title><content type='html'>&lt;br /&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;I know this may sound verysimplistic but perhaps a common mistake everyone may make – at least I did. You’reto find out what is the maximum length between two strings. You might betempted to do the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;maxLength=s.length()&amp;gt;t.length() ? s.length() : t.length();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Alright this looks nice,maybe professional and C-style for sure, but how about the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;maxLength=s.length();&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;(t.length()&amp;gt;maxLength)&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;maxLength=t.length();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Note that in the lattercase, your doing only two function calls.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-2071636157040192963?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/2071636157040192963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=2071636157040192963' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/2071636157040192963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/2071636157040192963'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/09/less-function-calls-wouldnt-kill.html' title='less function calls wouldn&apos;t kill ...'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-5509531843821814243</id><published>2011-07-22T15:02:00.001-07:00</published><updated>2011-12-27T08:01:39.442-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Event Listener'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Implementing a customized event listener</title><content type='html'>&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;You’ve been perhaps using listeners/handlers but it would be nice to implement your own. A good example is when you have a class for managing global settings in your application, which many other classes refer to retrieve different types of settings such as default language, color or size. This is one way to implement this pattern:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;First, you need an interface:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;interface&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; SettingsListener {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; onChange();&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt; line-height: 115%;"&gt;}&lt;/span&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Every Class implementing this interface will then use its own specific strategy to deal with new changes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Second, in your settings class add a collection to hold all listeners:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;private&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; Set&amp;lt;SettingsListener&amp;gt;&lt;settingslistener&gt; &lt;/settingslistener&gt;&lt;/span&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;settingsListeners&lt;/span&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; HashSet&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 12px;"&gt;&amp;lt;SettingsListener&amp;gt;();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Using the interface &lt;i&gt;Set&lt;/i&gt;, we ensure only one instance of each object is added here. Now, in every method of the settings class, where a change occurs, you need to call the &lt;i&gt;onChange&lt;/i&gt; method of all listeners:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;for&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; (SettingsListener sl : &lt;/span&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;settingsListeners&lt;/span&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;) {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sl.&lt;span style="background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial;"&gt;onChange&lt;/span&gt;();&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;}&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Oops! I almost forgot. The settings class needs a method to add change listeners:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;span style="background-attachment: initial; background-clip: initial; background-color: silver; background-image: initial; background-origin: initial;"&gt;addChangeListener&lt;/span&gt;(SettingsListener settingsListener) {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;settingsListeners&lt;/span&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;.add(settingsListener);&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;}&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Finally, you’ll make all classes that refer to settings to read a change implement the &lt;i&gt;SettingsListener&lt;/i&gt; interface. For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; A &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;implements&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; SettingsListener {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; A() {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;...&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Settings.addChangeListener(&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;);&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;...&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: #646464; font-family: 'Courier New'; font-size: 9pt;"&gt;@Override&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: 'Courier New'; font-size: 9pt;"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt; onChange() {&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;"&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;language=Settings.getLanguage()&lt;/span&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm; mso-layout-grid-align: none; text-autospace: none; text-indent: 36.0pt;"&gt;&lt;span style="color: #0000c0; font-family: 'Courier New'; font-size: 9pt;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: 'Courier New'; font-size: 9pt;"&gt;}&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;"&gt;Other classes may need taking color or size or anything else within their &lt;i&gt;onChange &lt;/i&gt;method. Note that you need to add this object to settings’ collection of change listeners. Settings might be an object or class depending how you implement it. But perhaps the best way is to implement it as a &lt;a href="http://once-upon-a-java.blogspot.com/2008/11/singletons-in-java.html"&gt;singleton&lt;/a&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-5509531843821814243?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/5509531843821814243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=5509531843821814243' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5509531843821814243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5509531843821814243'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/07/implementing-customized-event-listener.html' title='Implementing a customized event listener'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-7516106800016414036</id><published>2011-07-14T13:22:00.000-07:00</published><updated>2011-12-27T08:01:39.452-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='For-Each'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Loop'/><title type='text'>Java For-Each Loop</title><content type='html'>&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13pt; line-height: 115%;"&gt;The conventional loop has another face in Java. This is sometimes useful especially when you’re doing the same thing to all members of a collection or array. That is you don’t really need a loop counter or collection iterator. Instead you can just use the for loop as follows&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;Example 1 – An Array:&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String[] languages={"Chinese", "Korean", "Japanese"} ;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (String l : languages) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(l);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;Example 2 – A Collection:&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HashSet&amp;lt;string&amp;gt; languages=new HashSet&amp;lt;string&amp;gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; languages.add("Chinese");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; languages.add("Korean");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; languages.add("Japanese");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (String l : languages) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(l);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="text-align: justify;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13pt; line-height: 115%;"&gt;This perhaps yields to better performance too as it imposes a data-level parallelism given that the application is running on multi-core – I’m not sure though ;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-7516106800016414036?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/7516106800016414036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=7516106800016414036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7516106800016414036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7516106800016414036'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/07/java-for-each-loop.html' title='Java For-Each Loop'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-4123896055103827358</id><published>2011-07-13T13:33:00.000-07:00</published><updated>2011-12-27T08:01:39.424-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='enum'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>The new Java enum type</title><content type='html'>&lt;div class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: 17px; line-height: 19px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Traditionally, programmers use static fields within classes to represent enum types. For example, in order to show a list of languages, a programmer would define a class like the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, sans-serif;"&gt;  &lt;table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0cm; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184; width: 75.26%;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;public class Language {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;UNKNOWN=0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;PERSIAN=1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;ENGLISH=2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;FRENCH=3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 4;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;ARABIC=4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 5;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 6;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;String[]&amp;nbsp;getAllLanguages()&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 7;"&gt;   &lt;td style="background: #FFFFCC; padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #FFFFCC; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String[]&amp;nbsp;languages={"Unknown",&amp;nbsp;"Persian",&amp;nbsp;"English",&amp;nbsp;"French",&amp;nbsp;"Arabic"};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 8;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;languages;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 9;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 10;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 11;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;int&amp;nbsp;getLanguageIndex(String&amp;nbsp;string)&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 12;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;TODO&amp;nbsp;Auto-generated&amp;nbsp;method&amp;nbsp;stub&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 13;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(string.compareToIgnoreCase("Persian")==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 14;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 15;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(string.compareToIgnoreCase("English")==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 16;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;2;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 17;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(string.compareToIgnoreCase("French")==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 18;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 19;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(string.compareToIgnoreCase("Arabic")==0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 20;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 21;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 22;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 23; mso-yfti-lastrow: yes;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Since Java 1.5, you can define enums using a more efficient, more flexible and more beautiful structure called enum. A simple enum for languages looks like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0cm; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184; width: 75.26%;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;public enum Language {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;UNKNOWN, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;PERSIAN,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ENGLISH,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;FRENCH,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ARABIC&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;In the above code, every constant is in fact an instance of the enum Language. Hence, they can all have their own constructor, fields and methods. For example, to add an string value representing every constant, you would do the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0cm; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184; width: 75.26%;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;public enum Language {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;UNKNOWN(“Unknown”), &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;PERSIAN(“Persian”),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ENGLISH(“English”),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;FRENCH(“French”),&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ARABIC(“Arabic”)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;private final String   languageName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;public Language(String name) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;lanuageName=name.toUpperCase();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;@Override&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;public String toString() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return languageName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;Also, to obtain the numeric value, you can add an abstract method and implement it for every constant to return the value you wish as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0cm; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184; width: 75.26%;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;public enum Language {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;UNKNOWN(“Unknown”) {public int index() {return 0} }, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;PERSIAN(“Persian”) {public   int index() {return 1} },&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ENGLISH(“English”) {public int index() {return 2} },&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;FRENCH(“French”) {public int index() {return 3} },&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&amp;nbsp;&amp;nbsp;ARABIC(“Arabic”) {public int index() {return 4} };&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;private final String   languageName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;public Language(String name) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;lanuageName=name.toUpperCase();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;@Override&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;public String toString() {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return languageName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;Public abstract in index();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;The following code uses the Language enum to fill in a list of languages&lt;/span&gt;:&lt;/div&gt;&lt;table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="mso-cellspacing: 0cm; mso-padding-alt: 0cm 0cm 0cm 0cm; mso-yfti-tbllook: 1184; width: 75.26%;"&gt;&lt;tbody&gt;&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0; mso-yfti-lastrow: yes;"&gt;   &lt;td style="padding: 0cm 0cm 0cm 0cm; width: 100.0%;" width="100%"&gt;   &lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;for (Language l : Language.values()) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/span&gt;languageList.addItem(l.toString());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;}&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Bitstream Vera Sans Mono&amp;quot;; font-size: 7.5pt; mso-bidi-font-family: &amp;quot;Courier New&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;The method values() returns all members of the enum. Accessing a certain member is as easy as the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;Language.FRENCH&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 13.0pt; line-height: 115%;"&gt;And accessing the numberic value of it would be follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #DDFFDD; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-CA;"&gt;Language.FRENCH.index();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-4123896055103827358?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/4123896055103827358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=4123896055103827358' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4123896055103827358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4123896055103827358'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/07/new-java-enum-type.html' title='The new Java enum type'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-8433941585896443717</id><published>2011-06-29T14:18:00.000-07:00</published><updated>2011-12-27T08:01:39.470-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DTD'/><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='SAXException'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>SAX Exception while deploying GWT Application on GAE</title><content type='html'>&lt;div class="MsoNormal"&gt;I just faced this problem while trying to deploy my GWT application on Google Application Engine. This is the message&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;An internal error occurred during: "Deploying ... to Google".&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;Received SAXException parsing the input stream for .../war\WEB-INF/web.xml&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;This, often, doesn’t have anything to do with the XML file but just in case, check the validity of your xml first. If the file is ok then the problem is simply that one of the websites your XML is referring to is down! In my case, java.sun.com was done, so go check those out. With the growing number of XMLs referring to reference sites such as Java’s this is becoming a typical problem so though sharing it would help.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-8433941585896443717?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/8433941585896443717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=8433941585896443717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8433941585896443717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8433941585896443717'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2011/06/sax-exception-while-deploying-gwt.html' title='SAX Exception while deploying GWT Application on GAE'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-7953840993712244050</id><published>2010-12-14T14:26:00.001-08:00</published><updated>2011-12-27T08:01:39.462-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Array'/><category scheme='http://www.blogger.com/atom/ns#' term='Comparator'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Sort'/><title type='text'>Sorting arrays using comparator</title><content type='html'>&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;div class="MsoNormal"&gt;Sorting arrays could be simply performed using the function &lt;i&gt;sort&lt;/i&gt; of the class &lt;i&gt;Arrays&lt;/i&gt;. This, however, needs implementing the interface &lt;i&gt;Comparator&lt;/i&gt; for the specific type you’re storing in the array. Consider the following Class:&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Car {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;double&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;cylinders&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;double&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Car(&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;double&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; s, &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; c, &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;double&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; g) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;=s;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;cylinders&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;=c;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;=g;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;span style="background: silver; mso-highlight: silver;"&gt;String&lt;/span&gt; toString() {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="background: silver; color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt; &lt;/span&gt;&lt;span style="background: silver; color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;"speed="&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;+&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;speed&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;+&lt;/span&gt;&lt;span style="background: silver; color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;" sylinders="&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;+&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;cylinders&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;+&lt;/span&gt;&lt;span style="background: silver; color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;"gas="&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;+&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="background: silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; mso-background-themecolor: background1; mso-background-themeshade: 242;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; line-height: 115%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;When sorting an arrays of cars we’d like to see cars sorted from minimum &lt;i&gt;speed&lt;/i&gt; to maximum &lt;i&gt;speed&lt;/i&gt; but from maximum &lt;i&gt;gas_per_mile&lt;/i&gt; to minimum one. We, thus, implement two comparators. Notice that the usage of comparator enables the developer to sort the array in any custom order required:&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;import&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; java.util.Comparator;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; GasComparator &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;implements&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Comparator&amp;lt;Car&amp;gt; {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #646464; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;@Override&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; compare(Car arg0, Car &lt;span style="background: silver; mso-highlight: silver;"&gt;arg1&lt;/span&gt;) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;// &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f9fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;TODO&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Auto-generated method stub&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; (arg0.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&amp;gt;&lt;span style="background: silver; mso-highlight: silver;"&gt;arg1&lt;/span&gt;.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; -1;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; (arg0.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&amp;lt;&lt;span style="background: silver; mso-highlight: silver;"&gt;arg1&lt;/span&gt;.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;gas_per_mile&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; 1;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; 0;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;import&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt; java.util.Comparator;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; SpeedComparator &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;implements&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Comparator&amp;lt;Car&amp;gt; {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #646464; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;@Override&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; compare(Car arg0, Car arg1) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;// &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f9fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;TODO&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; Auto-generated method stub&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; (arg0.&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&amp;lt;arg1.&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; -1;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; (arg0.&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&amp;gt;arg1.&lt;/span&gt;&lt;span style="background: silver; color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt; mso-highlight: silver;"&gt;speed&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;)&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; 1;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;return&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt; 0;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 9.0pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;The interface &lt;i&gt;Comparator&lt;/i&gt; implements the function &lt;i&gt;compare&lt;/i&gt;, which returns an integer value. The most common use is to return -1 if arg0 is smaller than arg1, return 1 if arg0 is bigger than arg1 and 0 elsewhere but as implemented in &lt;i&gt;GasComparator&lt;/i&gt; one may use other ways of comparison as well. Try the following test program:&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;import&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; java.util.*;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; Test {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f5fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;/**&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f5fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;*&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f9fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;@param&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; &lt;/span&gt;&lt;span style="color: #3f5fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;args&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f5fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;*/&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;public&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;static&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;void&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; main(String[] args) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;// &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f9fbf; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;TODO&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #3f7f5f; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; Auto-generated method stub&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Car[] cars={&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; Car(225.0,6,10.5),&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; Car(215.5,4,12.5),&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; Car(320,6,15.5)};&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Arrays.&lt;i&gt;sort&lt;/i&gt;(cars, &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; SpeedComparator());&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background: silver; mso-highlight: silver;"&gt;System&lt;/span&gt;.&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;.println(&lt;/span&gt;&lt;span style="color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;"sorting based on maximum speed"&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;);&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;for&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; (&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; i=0;i&amp;lt;cars.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;length&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;;i++) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background: silver; mso-highlight: silver;"&gt;System&lt;/span&gt;.&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;.println(cars[i].toString());&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background: silver; mso-highlight: silver;"&gt;System&lt;/span&gt;.&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;.println(&lt;/span&gt;&lt;span style="color: #2a00ff; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;"now sorting based on gas usage"&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;);&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Arrays.&lt;i&gt;sort&lt;/i&gt;(cars, &lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; GasComparator());&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;for&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; (&lt;/span&gt;&lt;b&gt;&lt;span style="color: #7f0055; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt; i=0;i&amp;lt;cars.&lt;/span&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;length&lt;/span&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;;i++) {&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="background: silver; mso-highlight: silver;"&gt;System&lt;/span&gt;.&lt;/span&gt;&lt;i&gt;&lt;span style="color: #0000c0; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;out&lt;/span&gt;&lt;/i&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;.println(cars[i].toString());&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 2;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 3;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;span style="mso-tab-count: 1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; mso-background-themecolor: background1; mso-background-themeshade: 242;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 8.0pt; line-height: 115%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;The output is as follows:&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;sorting based on maximum speed&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=215.5 sylinders=4 gas=12.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=225.0 sylinders=6 gas=10.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=320.0 sylinders=6 gas=15.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;now sorting based on gas usage&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=320.0 sylinders=6 gas=15.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=215.5 sylinders=4 gas=12.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="background: #F2F2F2; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; mso-background-themecolor: background1; mso-background-themeshade: 242; mso-layout-grid-align: none; text-autospace: none;"&gt;&lt;span style="color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;speed=225.0 sylinders=6 gas=10.5&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;note that the array is first sorted based on speed from min to max, then sorted base on gas usage from max to min.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-7953840993712244050?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/7953840993712244050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=7953840993712244050' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7953840993712244050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7953840993712244050'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2010/12/sorting-arrays-using-comparator.html' title='Sorting arrays using comparator'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-2738377394017643447</id><published>2010-12-11T07:02:00.000-08:00</published><updated>2011-12-27T08:01:39.413-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='package'/><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='sub-package'/><category scheme='http://www.blogger.com/atom/ns#' term='subpackage'/><category scheme='http://www.blogger.com/atom/ns#' term='&quot;No source code is available for the type ...&quot; Error'/><title type='text'>Sub-packaging in Eclipse</title><content type='html'>I created a UI widget for a GWT project in Eclipse. But I wanted to separate logic from UI, so I created a UI package and moved the widget class to this new package. This resulted in an error saying GWT compiler cannot access the code for the widget: "No source code is available for ...". I realized, the widget code should be in the same folder/package of the package client. But Eclipse doesn’t allow creating a sub-package. So the problem turned out to be this: In a project, e.g. &lt;i&gt;proj1&lt;/i&gt;, how can I create a sub-package, e.g. &lt;i&gt;ui &lt;/i&gt;under another package, e.g. &lt;i&gt;client&lt;/i&gt;? The answer is as simple as this, rename the package &lt;i&gt;ui &lt;/i&gt;to &lt;i&gt;client.ui&lt;/i&gt; or if your package names are trailed by the project name, change its name from &lt;i&gt;proj1.ui&lt;/i&gt; to &lt;i&gt;proj1.client.ui&lt;/i&gt;. Having done this, your package still appears as an independent one in Eclipse but if you soar to your eclipse workspace, you’ll see that the folder ui appears under the folder client.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-2738377394017643447?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/2738377394017643447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=2738377394017643447' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/2738377394017643447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/2738377394017643447'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2010/12/sub-packaging-in-eclipse.html' title='Sub-packaging in Eclipse'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-186239720116337673</id><published>2010-06-23T21:57:00.000-07:00</published><updated>2011-12-27T08:01:39.400-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='JDBC'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>GWT and Database? Huh?</title><content type='html'>&lt;div&gt;I’m assuming you’re using Eclipse-based Google Web Toolkit (GWT). If you try to connect to database using JDBC in GWT you will face several problems. First thing, if you receive a ClassNotFoundException on your JDBC driver, make sure you have done the followings to get rid of it:&lt;/div&gt;&lt;div&gt;1-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Add the driver JAR to your application classpath&lt;/div&gt;&lt;div&gt;2-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Copy the driver JAR under you application’s war/web-inf/lib folder&lt;/div&gt;&lt;div&gt;But that’s not even the half of the problem. The real issue is with getting connected to the database, which is not possible – at least as far as I’ve tried – under GWT’s default server simply because it does not permit socket connections to proceed and there’s no way to add such permissions as a java policy file or something like that.&lt;/div&gt;&lt;div&gt;I suggest using Tomcat instead. Here’s what you do (In Eclipse – I’m using Europa):&lt;/div&gt;&lt;div&gt;1-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Create an XML file under your project folder with the following contents:&lt;/div&gt;&lt;div&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;&amp;lt;project name="yourprojectname" basedir="." default="default"&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt;&lt;/span&gt; &amp;lt;target name="default" depends="buildwar,deploy"&amp;gt;&amp;lt;/target&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt;&lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;&lt;/span&gt;  &amp;lt;target name="buildwar"&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;&lt;/span&gt;   &amp;lt;war basedir="war" destfile="yourprojectname.war" webxml="war/WEB-INF/web.xml"&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;&lt;/span&gt;    &amp;lt;exclude name="WEB-INF/**" /&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;&lt;/span&gt;    &amp;lt;webinf dir="war/WEB-INF/"&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:4"&gt;&lt;/span&gt;     &amp;lt;include name="**/*.jar" /&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;&lt;/span&gt;    &amp;lt;/webinf&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;&lt;/span&gt;   &amp;lt;/war&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:1"&gt;&lt;/span&gt;  &amp;lt;/target&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt;&lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;&lt;/span&gt;  &amp;lt;target name="deploy"&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;&lt;/span&gt;   &amp;lt;copy file="yourprojectname.war" todir="." /&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:1"&gt;&lt;/span&gt;  &amp;lt;/target&amp;gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpLast"&gt;&lt;span style="mso-spacerun:yes"&gt;&lt;/span&gt; &amp;lt;/project&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;code&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;project name="yourprojectname" basedir="." default="default"&gt;&lt;/project&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;               &lt;/span&gt;&lt;target name="default" depends="buildwar,deploy"&gt;&lt;/target&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;               &lt;/span&gt;&lt;target name="buildwar"&gt;&lt;/target&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;                                &lt;/span&gt;&lt;war basedir="war" destfile="yourprojectname.war" webxml="war/WEB-INF/web.xml"&gt;&lt;/war&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;                                                &lt;/span&gt;&lt;exclude name="WEB-INF/**"&gt;&lt;/exclude&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;                                                &lt;/span&gt;&lt;webinf dir="war/WEB-INF/"&gt;&lt;/webinf&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:4"&gt;                                                                &lt;/span&gt;&lt;include name="**/*.jar"&gt;&lt;/include&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:3"&gt;                                                &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;                                &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:1"&gt;                &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;span style="mso-tab-count:1"&gt;               &lt;/span&gt;&lt;target name="deploy"&gt;&lt;/target&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:2"&gt;                                &lt;/span&gt;&lt;copy file="yourprojectname.war" todir="."&gt;&lt;/copy&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpMiddle"&gt;&lt;span style="mso-tab-count:1"&gt;                &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;&lt;/p&gt;&lt;/code&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;&lt;/p&gt;&lt;p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"&gt;&lt;span style="mso-bidi-mso-bidi-theme-font:minor-latin;font-family:Calibri;"&gt;&lt;span style="mso-list:Ignore"&gt;2-&lt;span style="font:7.0pt &amp;quot;Times New Roman&amp;quot;"&gt;    2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;-&lt;span class="Apple-tab-span" style="white-space: pre; "&gt; &lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space: pre; "&gt; &lt;/span&gt;Make sure your code is good to the best of your knowledge&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpFirst"&gt;3-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Clean your project: Project Menu – Clean&lt;/p&gt;&lt;/div&gt;&lt;div&gt;4-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Right Click on your project. Select Google -&gt; GWT Compile. This might take a few moments to complete.&lt;/div&gt;&lt;div&gt;5-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Right Click on you project. Select Export – Jar File – Make sure only the src folder of your project is selected. The destination should be under your project folder in …/war/web-inf/lib.&lt;/div&gt;&lt;div&gt;6-&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;Right click on the xml file created in the first step and select Ant Build.&lt;/div&gt;&lt;div&gt;If everything goes well, you are going to see a war file under your project folder. Copy this under the webapps folder of your tomcat; I suggest downloading a recent version of Tomcat. If this is not your first time, stop Tomcat, delete the project under webapps devoted to your project if any, start it again. Check if a folder for you project is created under tomcat and if it’s not empty. Open you browser and go to http://localhost:8080/yourprojectname&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;p.s. GWT has its own internal datastore mechanism, which is less know to most developers. This post addresses those who wish to use GWT with their own preference of database.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-186239720116337673?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/186239720116337673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=186239720116337673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/186239720116337673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/186239720116337673'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2010/06/gwt-and-database-huh.html' title='GWT and Database? Huh?'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-8151141639340024855</id><published>2009-02-22T19:50:00.000-08:00</published><updated>2011-12-27T08:01:39.466-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='I/O'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Reading an XML File in Java</title><content type='html'>The following code is all you need to open an XML file using Java:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;public static void openXML(String xmlFile) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     try {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   DocumentBuilderFactory docBuilderFactory = &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;DocumentBuilderFactory.newInstance();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   Document xmlProfile = docBuilder.parse (new File(xmlFile));&lt;/span&gt;&lt;br /&gt;   &lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   ...&lt;/span&gt;&lt;br /&gt;   &lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;  } catch (ParserConfigurationException pce) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   System.out.println("ParserConfigurationException: " + pce.toString());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;  } catch (IOException ioe) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   System.out.println("IOException: " + ioe.toString());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;  } catch (SAXException sxe) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;   System.out.println("SAXException: " + sxe.toString());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You would need the following inclusions:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import javax.xml.parsers.DocumentBuilder;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import javax.xml.parsers.DocumentBuilderFactory;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import javax.xml.parsers.ParserConfigurationException;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import org.w3c.dom.Document;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;import org.xml.sax.SAXException;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span style="font-style: italic;"&gt;xmlProfile&lt;/span&gt; provides you the facilities you require to read XML elements. Some useful methods are:&lt;br /&gt;&lt;span style="font-style: italic;"&gt;getChildNodes()&lt;/span&gt;, returns a list of all children.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;getElementsByTagName(String aName)&lt;/span&gt;, finds all elements tagged as aName&lt;br /&gt;&lt;span style="font-style: italic;"&gt;getAttributes()&lt;/span&gt;, returns a list of attributes.&lt;br /&gt;&lt;br /&gt;Methods usually return a list such as &lt;span style="font-style: italic;"&gt;NodeList&lt;/span&gt;. Items can be accessed using item method. For example the following code prints all the attributes of a selected node:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;  for (int i=0;i&lt;/span&gt;&lt;node.getattributes().getlength();i++)&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;&lt;node.getattributes().getlength();i++)&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;&lt;/span&gt;&lt;/node.getattributes().getlength();i++)&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;node.getattributes().getlength();i++)&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;   String attrName=node.getAttributes().item(i).getNodeName();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;&lt;/span&gt;&lt;/node.getattributes().getlength();i++)&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;node.getattributes().getlength();i++)&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;   String attrVal=node.getAttributes().item(i).getNodeValue();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;&lt;/span&gt;&lt;/node.getattributes().getlength();i++)&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(0, 204, 204);"&gt;     &lt;/span&gt;&lt;node.getattributes().getlength();i++)&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;   System.out.println(attrName+ “ “+ attrVal);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic; color: rgb(0, 204, 204);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/node.getattributes().getlength();i++)&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-8151141639340024855?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/8151141639340024855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=8151141639340024855' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8151141639340024855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8151141639340024855'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2009/02/reading-xml-file-in-java.html' title='Reading an XML File in Java'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-5686354635339736239</id><published>2009-01-14T17:51:00.000-08:00</published><updated>2011-12-27T08:01:39.445-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='I/O'/><category scheme='http://www.blogger.com/atom/ns#' term='Console'/><title type='text'>Input from Console</title><content type='html'>It's amazingly a very common question. The truth is it was an annoying job to read things from command line in Java before Java 5.x. Now the Scanner class has made things easy. This is how you do it for a simple integer input:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;  Scanner scanner=new Scanner(System.in);&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;  System.out.println("Eneter a number between 1 to 100:");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;  int num=scanner.nextInt();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One may even use the following loop to read more than one input at once:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;  while (scanner.hasNext()) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;       num=scanner.nextInt();&lt;/span&gt;&lt;br /&gt;   &lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;     ...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the loop reads from input while there is input to read. Other methods such as &lt;span style="font-style: italic; font-weight: bold; color: rgb(51, 204, 255);"&gt;nextString, nextLong, nextDouble&lt;/span&gt;, ... read other types of data. It is also possible to provide a pattern to read according to: &lt;span style="font-weight: bold; font-style: italic; color: rgb(51, 204, 255);"&gt;scanner.read(“a*b”); hasNext&lt;/span&gt; method used in the above loop could also be applied to specific types or patterns.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-5686354635339736239?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/5686354635339736239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=5686354635339736239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5686354635339736239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/5686354635339736239'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2009/01/input-from-console.html' title='Input from Console'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-3257648874931947383</id><published>2009-01-11T09:19:00.000-08:00</published><updated>2011-12-27T08:01:39.416-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Dialog'/><title type='text'>Java Dialog Box</title><content type='html'>One may always extend a complex window class such as Jframe to create a dialogh box in Java. However, there is a quick way for building simple dialog boexs such as message box or input box. This is provided using JoptionPane, a class accessible through javax.swing. JoptionPane has four useful methods:&lt;br /&gt;&lt;br /&gt;showConfirmDialog: Asks a confirming question, like yes/no/cancel.&lt;br /&gt;ShowInputDialog: Prompt for some input.&lt;br /&gt;ShowMessageDialog: Tell the user about something that has happened.&lt;br /&gt;ShowOptionDialog: a mix of all three above.&lt;br /&gt;&lt;br /&gt;Exampes of ShowInputDialog, which I use a lot:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#00cccc;"&gt;String name=JOptionPane.showInputDialog("What's your name?");&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;Inputs a name&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#00cccc;"&gt;&lt;em&gt;String[] selectionValues={"ONE", “TWO”, “THREE”};&lt;br /&gt;String defaultSelection = "ONE";&lt;br /&gt;Object selection = JOptionPane.showInputDialog(null, "Select a number",&lt;br /&gt;"NUMBER SELECTION", JOptionPane.QUESTION_MESSAGE, null, selectionValues, defaultSelection);&lt;/em&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;shows a dropdown selection box. There are 7 parameters:&lt;br /&gt;&lt;br /&gt;1- Just leave it null. Indicates the parent component though.&lt;br /&gt;2- Message&lt;br /&gt;3- Title&lt;br /&gt;4- Type of ICON. Could be any/mix of ERROR/INFORMATION/WARNING/QUESTION/PLAIN_Message&lt;br /&gt;5- The buttons you'd like in your dialog. Leave it null for a simple OK button. Other options are: DEFAULT_OPTION/YES_NO_OPTION/YES_NO_CANCEL_OPTION/OK_CANCEL_OPTION&lt;br /&gt;6- The array of selection values&lt;br /&gt;7- default item&lt;br /&gt;&lt;br /&gt;Confirm Dialog is also interesting. This is how I use a simple instance:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="color:#33ccff;"&gt;int login=JOptionPane.showConfirmDialog(null, "Is login required to browse this page?", "Login Check", JoptionPane.YES_NO_OPTION);&lt;br /&gt;if (login==JOptionPane.YES_OPTION)&lt;br /&gt;...&lt;br /&gt;else&lt;br /&gt;...&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-3257648874931947383?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/3257648874931947383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=3257648874931947383' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/3257648874931947383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/3257648874931947383'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2009/01/one-may-always-extend-complex-window.html' title='Java Dialog Box'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-1161660052291039107</id><published>2008-12-20T21:51:00.000-08:00</published><updated>2011-12-27T08:01:39.393-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Dialog'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>Open File Dialog in Java</title><content type='html'>The easiest way to create an Open File Dialog - that I'm aware of - in java is to use JFileChooser. This is relatively easy. Just look at the following exerpt of code:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:#33ccff;"&gt;import javax.swing.*;&lt;br /&gt;import javax.swing.filechooser.*;&lt;br /&gt;...&lt;br /&gt;1: JFileChooser fd = new JFileChooser(".");&lt;br /&gt;2: ExampleFileFilter filter = new ExampleFileFilter();&lt;br /&gt;3: filter.addExtension("tst");&lt;br /&gt;4: fd.setFileFilter(filter);&lt;br /&gt;5: int returnVal = fd.showOpenDialog(null);&lt;br /&gt;6: if(returnVal == JFileChooser.APPROVE_OPTION) {&lt;br /&gt;7: String fileName=fd.getSelectedFile().getName();&lt;br /&gt;8: }&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;Line 1 creates a simple file chooser that opens a dialog in the current path/directory. “.” stands for the current path; that is the path in which your program runs. One may change this according to his/her program requirements.&lt;br /&gt;Line 2 creates a file filter. Line 3 adds an extension to this file filter and Line 4 adds the filter to the dialog.&lt;br /&gt;Line 5 shows the the dialog. Return value is stored within an integer variable that shows the status of the dialog. If the a file was successfully chosen, selected file name may be obtained as shown in Line 7.&lt;br /&gt;But wait a minute ... what is the example file filter? frankly speaking, creating a file filter could be a headache. Fortunately, an ExampleFileFilter is available from &lt;a href="http://www.vaegar.f9.co.uk/examples/SwingSet_demo/ExampleFileFilter.java.html"&gt;Sun's website&lt;/a&gt;. My Suggestion, just download it and use it as it is.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-1161660052291039107?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/1161660052291039107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=1161660052291039107' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/1161660052291039107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/1161660052291039107'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/12/open-file-dialog-in-java.html' title='Open File Dialog in Java'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-8841787939277157127</id><published>2008-12-05T16:33:00.000-08:00</published><updated>2011-12-27T08:01:39.474-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='File'/><title type='text'>File Buffered Read/Write</title><content type='html'>Reading/writing files in Java may be done in a variety of ways. The most efficient way is probably to use serializable objects and IO streams. But for this post I’ll review an even simpler approach using buffered writer/readers. The following example contains the methods required for writing and reading a file. One may add as much as information required. The problem with this approach is that it’s not efficient and that both the reader and writer must be aware of each other, which is a bit against object-oriented ideas behind Java but it’s ok for a small experience:&lt;br /&gt;&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.BufferedWriter;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt;import java.io.FileReader;&lt;br /&gt;import java.io.FileWriter;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;public class Test {&lt;br /&gt; &lt;br /&gt;    private static void save() {&lt;br /&gt;  File helloFile=new File("HelloWorld.txt");&lt;br /&gt; &lt;br /&gt;  BufferedWriter output = null;&lt;br /&gt;     try {&lt;br /&gt;       output = new BufferedWriter( new FileWriter(helloFile) );&lt;br /&gt;       output.write("Helo World!");&lt;br /&gt;       &lt;br /&gt;    } catch(FileNotFoundException e) {&lt;br /&gt;        e.printStackTrace();&lt;br /&gt;    } catch (IOException e) {&lt;br /&gt;        e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;    finally {&lt;br /&gt;       try {&lt;br /&gt;         if (output!= null) {&lt;br /&gt;           output.close();&lt;br /&gt;         }&lt;br /&gt;       }&lt;br /&gt;       catch (IOException ex) {&lt;br /&gt;         ex.printStackTrace();&lt;br /&gt;       }&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private static String load() {&lt;br /&gt;      File helloFile=new File("HelloWorld.txt");&lt;br /&gt;     &lt;br /&gt;      BufferedReader input = null;&lt;br /&gt;         try {&lt;br /&gt;           input = new BufferedReader( new FileReader(helloFile) );&lt;br /&gt;           String helloWorld=input.readLine();&lt;br /&gt;           &lt;br /&gt;            return helloWorld;&lt;br /&gt;        } catch(FileNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            return "FileNotFound";&lt;br /&gt;        } catch (IOException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            return "IO Error";&lt;br /&gt;        }&lt;br /&gt;     finally {&lt;br /&gt;        try {&lt;br /&gt;          if (input!= null) {&lt;br /&gt;            input.close();&lt;br /&gt;          }&lt;br /&gt;        }&lt;br /&gt;        catch (IOException ex) {&lt;br /&gt;          ex.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        save();&lt;br /&gt;        String hello=load();&lt;br /&gt;        System.out.println(hello);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-8841787939277157127?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/8841787939277157127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=8841787939277157127' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8841787939277157127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/8841787939277157127'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/12/file-buffered-readwrite.html' title='File Buffered Read/Write'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-4725420990039871307</id><published>2008-11-29T15:45:00.000-08:00</published><updated>2011-12-27T08:01:39.428-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Singleton'/><title type='text'>Singletons in Java</title><content type='html'>Singleton is a design pattern (ok, design patterns are to be discussed in another note!) that guarantees a certain object will only have one single instance at runtime. This is sometimes required if different versions/threads/extensions of the program might try to re-initialize a specific object without knowledge of each other. There are serious discussions if Singleton is required in Java at all and I will discuss this later in a separate post but for now just consider it as yet another way of doing things. The basic way of creating a singleton is as follows:&lt;br /&gt;&lt;br /&gt;public class Singleton {&lt;br /&gt;private static Singleton instance=null;&lt;br /&gt;&lt;br /&gt;public static Singleton getInstance() {&lt;br /&gt;            if (instance==null)&lt;br /&gt;                        instance=new Singleton();&lt;br /&gt;            return instance;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Some good questions:&lt;br /&gt;- What if someone tries to make a new instance of the singleton? Nothing because method and attribute are both static.&lt;br /&gt;- What if two applications call getInstance() simultaneously? Good question,  you may make it a synchronized entity. Just change the declaration to&lt;br /&gt;&lt;br /&gt;public static synchronized Singleton getInstance()&lt;br /&gt;&lt;br /&gt;- What if a naughty girl tricks the program by cloning the singleton object? Just override the clone method of your Singleton class as follows:&lt;br /&gt;&lt;br /&gt;public Object clone() throws CloneNotSupportedException {&lt;br /&gt;            throw new CloneNotSupportedException();&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-4725420990039871307?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/4725420990039871307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=4725420990039871307' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4725420990039871307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4725420990039871307'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/11/singletons-in-java.html' title='Singletons in Java'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-114642621103973951</id><published>2008-11-21T11:30:00.000-08:00</published><updated>2011-12-27T08:01:39.389-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='ClassCastException'/><title type='text'>Flexible Type Checking with Java Exceptions</title><content type='html'>If you have always thought that exceptions are only good to catch errors, this post may change your understanding of Java exceptions. Today, I’m going to mention a different application of exceptions that is to use them for identifying the type of an object. Consider a situation, where you have different objects inheriting from an upper-hand object. For example, a profile creation system that registers different types of members may have the following hierarchy:&lt;br /&gt;&lt;br /&gt;class Member {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Student extends Member {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Teacher extends Member {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The main registration facility is the same for both types so the developer decides to create one register method. However, in each case the system should take a different strategy for setting up members’ profile. Amongst other ways to doing so I describe the technique of using Java exceptions:&lt;br /&gt;&lt;br /&gt;public Profile createProfile(Member newMember) {&lt;br /&gt;try {&lt;br /&gt;            Student newStudent=(Student)newMember;&lt;br /&gt;…&lt;br /&gt;} catch (ClassCastException cce) {&lt;br /&gt;try {&lt;br /&gt;                        Teacher newTeacher=(Teacher)newMember;&lt;br /&gt;…&lt;br /&gt;} catch (ClassCastException cce) {&lt;br /&gt;            …&lt;br /&gt;}&lt;br /&gt;}}&lt;br /&gt;&lt;br /&gt;The first class casting tries to convert the newMember object to a Student object; if not successful the flow is trapped in the catch block, where there is another class cast operation towards a Teacher object. The cascade may go on for as many objects as extend the main Member object.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-114642621103973951?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/114642621103973951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=114642621103973951' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/114642621103973951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/114642621103973951'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/11/flexible-type-checking-with-java.html' title='Flexible Type Checking with Java Exceptions'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-4963521750623777763</id><published>2008-10-27T03:55:00.000-07:00</published><updated>2011-12-27T08:01:39.439-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Iterator'/><title type='text'>Iterators</title><content type='html'>You might have heard of Iterators; if not you should know they’re used to iterate over a collection. Iterators can replace the traditional way of defining a counter for looping. This is a more object-oriented way of doing things. Collections usually have an operation, &lt;em&gt;iterator()&lt;/em&gt;, which provides the iterator for further use. The following example shows how to use an iterator over an array:&lt;br /&gt;&lt;br /&gt;Import java.util.ArrayList;&lt;br /&gt;Import java.util.Iterator;&lt;br /&gt;&lt;br /&gt;…&lt;br /&gt;&lt;br /&gt;ArrayList&lt;student&gt; students;&lt;br /&gt;&lt;br /&gt;…&lt;br /&gt;&lt;br /&gt;Iterator studentIterator=students.iterator();&lt;br /&gt;While (studentIterator.hasNext()) {&lt;br /&gt;            Student currentStudent=(Student)studentIterator.next(); // The &lt;em&gt;next()&lt;/em&gt; method returns an object. You should typecast it before using it.&lt;br /&gt;            // do something with currentStudent&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-4963521750623777763?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/4963521750623777763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=4963521750623777763' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4963521750623777763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/4963521750623777763'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/10/iterators.html' title='Iterators'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7008884275520011766.post-7716854778557705334</id><published>2008-09-24T06:40:00.000-07:00</published><updated>2011-12-27T08:01:39.455-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Once Upon a Java</title><content type='html'>Once upon a time there was ME, MY PHD THESIS and A LOT OF JAVA WORK! ME was really in love with open source, open mind, open doors, open .... So ME decided to open A LOT OF JAVA WORK that I had to do in MY PHD THESIS to others. Hopefully, this way Liberals will win all the upcoming elections!!!&lt;br /&gt;&lt;br /&gt;Ok! Java has been programmers' favorite taste for a while now. I'm only here to expose simple small tips in Java as occurs in my own expereince. The first tip is obviosuly to not drink your coffee when it's so hot nor to drink it all at once. A cup of coffee must be drunk gently so that it cools down and coooools you down! Java is no exception. Stay tuned ... be back soooooooon!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7008884275520011766-7716854778557705334?l=once-upon-a-java.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://once-upon-a-java.blogspot.com/feeds/7716854778557705334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7008884275520011766&amp;postID=7716854778557705334' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7716854778557705334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7008884275520011766/posts/default/7716854778557705334'/><link rel='alternate' type='text/html' href='http://once-upon-a-java.blogspot.com/2008/09/once-upon-java.html' title='Once Upon a Java'/><author><name>Ali Fatolahi</name><uri>https://profiles.google.com/105182486812676181575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-q9vki0XqJAs/AAAAAAAAAAI/AAAAAAAAAXU/IXQPPGCCXCo/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
