<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Tre e mezzo [JJRumi's blog]</title>
	<link>http://www.jjrumi.com/blog</link>
	<description>A little more code. Programming, projects and digressing.</description>
	<pubDate>Mon, 30 Oct 2006 13:13:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>
	<language>en</language>
			<item>
		<title>TFC - Ubuntu 6.06 &#038; Tomcat 5</title>
		<link>http://www.jjrumi.com/blog/2006/10/30/tfc-ubuntu-606-tomcat-5/</link>
		<comments>http://www.jjrumi.com/blog/2006/10/30/tfc-ubuntu-606-tomcat-5/#comments</comments>
		<pubDate>Mon, 30 Oct 2006 13:10:05 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>TFC</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/10/30/tfc-ubuntu-606-tomcat-5/</guid>
		<description><![CDATA[After doing some UML work, it&#8217;s time to install the application server. I&#8217;ve choosen Apache Tomcat.
INSTALLATION:
To install tomcat I used:
:~$ sudo apt-get install apache2 tomcat5 tomcat5-webapps tomcat5-admin
With apache2 and tomcat5 I installed the application server.
tomcat5-webapps includes documentation and examples (always useful to have something to look at).
tomcat5-admin provides a web interface for administration tasks.
To use [...]]]></description>
			<content:encoded><![CDATA[<p>After doing some UML work, it&#8217;s time to install the application server. I&#8217;ve choosen <a href="http://tomcat.apache.org/">Apache Tomcat</a>.</p>
<p><strong><u>INSTALLATION:</u></strong></p>
<p>To install tomcat I used:<br />
<em>:~$ sudo apt-get install apache2 tomcat5 tomcat5-webapps tomcat5-admin</em></p>
<p>With <em>apache2</em> and <em>tomcat5</em> I installed the application server.<br />
<em>tomcat5-webapps</em> includes documentation and examples (always useful to have something to look at).<br />
<em>tomcat5-admin</em> provides a web interface for administration tasks.</p>
<p>To use the above command, one needs to add some extra repositories (Multiverse repository). <a href="http://ubuntuguide.org/wiki/Dapper#Repositories">Further information</a>.</p>
<p>To start/restart Tomcat: <em>:~$ sudo /etc/init.d/tomcat5 [start|restart]</em><br />
Tomcat&#8217;s default configuration sets listening port to 8180, so acceding http://localhost:8180 will be enough.<br />
In the page displayed is an important note:<br />
&#8220;NOTE: For security reasons, using the administration webapp is restricted to users with role &#8220;admin&#8221;. The manager webapp is restricted to users with role &#8220;manager&#8221;.  Users are defined in $CATALINA_HOME/conf/tomcat-users.xml.&#8221;</p>
<p>The examples (<em>tomcat5-webapps</em>) were installed at <strong>/usr/share/tomcat5/webapps/ </strong><br />
<strong>/etc/default/tomcat5</strong> includes some important variables (such as JAVA_HOME, CATALINA_BASE, LOGFILE_DAYS, etc&#8230;)<br />
The configuration files (server.xml y web.xml) are located at <strong>/etc/tomcat5/ </strong><br />
<strong>/var/lib/tomcat5/</strong> is the base directory of my Tomcat installation and <strong>/var/lib/webapps/ </strong>is where the the web applications should be located.</p>
<p><strong><u>FIRST WEB APPLICATION:</u></strong><br />
Now it&#8217;s time to add the first webapp.</p>
<p>Tomcat uses the WAR structure.</p>
<p>Standard Directory Layout &#8211;> Where are we playing today?</p>
<p>* /WEB-INF/web.xml &#8211;> This is an XML file describing the servlets and other components that make up your application.</p>
<p>* /WEB-INF/classes/ &#8211;> This directory contains any Java class files (and associated resources) required for your application.<br />
It&#8217;s important to note that a Java class named <em>com.mycompany.mypackage.MyServlet</em> would need to be stored in a file named<em> /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class</em>. </p>
<p>* /WEB-INF/lib/ &#8211;> This directory contains JAR files that contain Java class files required for your application.<br />
If you want a JAR to be visible for all of your webapps, place it in /var/lib/tomcat5/shared/lib</p>
<p>We can use the webapp http://localhost:8180/manager/html for deploy our applications.</p>
<p><a href="http://tomcat.apache.org/tomcat-5.0-doc/manager-howto.html">Further information</a> for the different possibilities of this tool.</p>
<p>I hope this will be enough for today <img src='http://www.jjrumi.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/10/30/tfc-ubuntu-606-tomcat-5/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Noam Chomsky</title>
		<link>http://www.jjrumi.com/blog/2006/09/29/noam-chomsky/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/29/noam-chomsky/#comments</comments>
		<pubDate>Fri, 29 Sep 2006 20:34:13 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>Digressing</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/09/29/noam-chomsky/</guid>
		<description><![CDATA[First of all, the presentations: Noam Chomsky
I&#8217;ve read this afternoon a column in the &#8216;Wall Street Journal - Europe&#8217; about Noam Chomsky. The author of the column was very critic with Chomsky, arguing more or less that &#8216;he&#8217;s biting the hand that feeds him&#8217; (refering to America).
I don&#8217;t agree with the author, because he used [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, the presentations: <a href="http://en.wikipedia.org/wiki/Noam_chomsky">Noam Chomsky</a></p>
<p>I&#8217;ve read this afternoon a column in the &#8216;Wall Street Journal - Europe&#8217; about Noam Chomsky. The author of the column was very critic with Chomsky, arguing <em>more or less</em> that &#8216;he&#8217;s biting the hand that feeds him&#8217; (refering to America).</p>
<p>I don&#8217;t agree with the author, because he used an Utopia to despise Chomky&#8217;s efforts to criticize the American foreign policy (since the end of the WWII until now).</p>
<p>The author assured that in America exist an almost recursive liberty and self-criticism that helps everyone to improve (socially and humanly). That&#8217;s not true. Chomsky has been shut up in many newspapers, tv programs and so on&#8230; just because of what he says.    </p>
<p>Aside from the Utopia, he based the other half of his speech in a lie: he sais everybody who isn&#8217;t American and is critic with it, want to be American&#8230;<br />
I want to tell him neither the American way is the best one, nor the only one.</p>
<p>I must confess I truly enjoy Chomsky&#8217;s books, they are really interesting and lets you with a different point of view of our Occidental society.</p>
<p>All this interest in Chomsky comes about because of last <a href="http://en.wikipedia.org/wiki/Hugo_chaves">Hugo Chaves</a>&#8216; declarations at the last meeting of the United Nations in New York, where he mentioned Chomsky (recommending a book of him).<br />
I&#8217;ll say Chomsky doesn&#8217;t need anybody to be known. He belongs to the <em>intelligentzia</em> of our century, and he&#8217;s well known because of his ideas.</p>
<p>But well&#8230;. WTF I know about America <img src='http://www.jjrumi.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/29/noam-chomsky/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Java - Instantiating an object dynamically</title>
		<link>http://www.jjrumi.com/blog/2006/09/20/java-instantiating-an-object-dynamically/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/20/java-instantiating-an-object-dynamically/#comments</comments>
		<pubDate>Wed, 20 Sep 2006 11:02:43 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>Java</category>
	<category>Tips</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/09/20/java-instantiating-an-object-dynamically/</guid>
		<description><![CDATA[If we ever need to instantiate a bunch of objects, and the order of instantiation needs to be set dynamically, we can take a good use of the class Class and its method forName which receives an String and returns a Class.
For example:
Class i = Class.forName(&#8221;java.lang.String&#8221;);
String x = (String)i.newInstance();

This would create an String&#8217;s instance in [...]]]></description>
			<content:encoded><![CDATA[<p>If we ever need to instantiate a <em>bunch</em> of objects, and the order of instantiation needs to be set dynamically, we can take a good use of the class Class and its method <em>forName</em> which receives an String and returns a Class.<br />
For example:</p>
<blockquote><p><em>Class i = Class.forName(&#8221;java.lang.String&#8221;);<br />
String x = (String)i.newInstance();<br />
</em></p></blockquote>
<p>This would create an String&#8217;s instance in x.</p>
<p>But there&#8217;s more, you can use this with the Constructor class.</p>
<p>Let&#8217;s suppose we have two objects (A,B) implementing an interface like this:</p>
<blockquote><p><em>interface IFigure{<br />
&nbsp;&nbsp;public void setName(String name);<br />
}<br />
class A implements IFigure{<br />
&nbsp;&nbsp;int idx;<br />
&nbsp;&nbsp;String name;</p>
<p>&nbsp;&nbsp;public A(){ idx=20; }<br />
&nbsp;&nbsp;public A(int i){ idx=i; }<br />
&nbsp;&nbsp;public String toString(){return &#8220;Obj_A(&#8221;+idx+&#8221;): &#8220;+this.name;}<br />
}</p>
<p>class B implements IFigure{<br />
&nbsp;int idx;<br />
&nbsp;String name;</p>
<p>&nbsp;public B(){ idx=10; }<br />
&nbsp;public B(int i){ idx= (i>0) ? (i*3) : 0; //if i>0 then idx=i*3 else i=0 }<br />
&nbsp;public void setName(String name){this.name = name;}<br />
&nbsp;public String toString(){return &#8220;Obj_B(&#8221;+idx+&#8221;): &#8220;+this.name;}<br />
}</p>
<p></em></p></blockquote>
<p>and we want to instantiate them, we can use this:</p>
<blockquote><p><em>//The classical way:<br />
A cA = new A();<br />
cA.setName(&#8221;Manolo&#8221;);<br />
System.out.println(cA);</p>
<p>//A dynamic way:<br />
try{<br />
&nbsp;&nbsp;Class generic = Class.forName(&#8221;A&#8221;);<br />
&nbsp;&nbsp;Constructor constructor[] = generic.getDeclaredConstructors();			</p>
<p>&nbsp;&nbsp;//Careful with the index of the array!!!!<br />
&nbsp;&nbsp;IFigure figObj = (IFigure) constructor[1].newInstance(new Object[0]); //equals new A();</p>
<p>&nbsp;&nbsp;figObj.setName(&#8221;Manolo&#8221;);</p>
<p>&nbsp;&nbsp;System.out.println(&#8221;A dynamic way: \n&#8221;+figObj);<br />
}catch(Exception e){<br />
&nbsp;&nbsp;e.printStackTrace();<br />
}<br />
</em></p></blockquote>
<p>In the last example, I&#8217;ve used the method <em>getDeclaredConstructors()</em> which returns an array with all the declared constructors of the class <strong>without</strong> an order.<br />
Because this is very annoying, we can use instead: </p>
<blockquote><p><em>Constructor c = generic.getConstructor(new Class[]{int.class})<br />
</em></p></blockquote>
<p>where we explicitly indicate which constructor we want to use.</p>
<p>Here is a whole example:</p>
<blockquote><p><em>/**<br />
 * @author Juan Luis Jiménez Rumí (www.jjrumi.com/blog)<br />
 *<br />
 */</p>
<p>import java.lang.*;<br />
import java.lang.reflect.Constructor;</p>
<p>interface IFigure{<br />
&nbsp;&nbsp;public void setName(String name);<br />
}</p>
<p>class A implements IFigure{<br />
&nbsp;&nbsp;int idx;<br />
&nbsp;&nbsp;String name;<br />
&nbsp;&nbsp;public A(){ idx=-999; }<br />
&nbsp;&nbsp;public A(int i){ idx=i; }<br />
&nbsp;&nbsp;public void setName(String name){ this.name = name; }<br />
&nbsp;&nbsp;public String toString() {return &#8220;Name_A: &#8220;+name+&#8221;. Idx: &#8220;+idx;}<br />
}</p>
<p>class B implements IFigure{<br />
&nbsp;&nbsp;int idx;<br />
&nbsp;&nbsp;String name;<br />
&nbsp;&nbsp;public B(){ idx=-999; }<br />
&nbsp;&nbsp;public B(int i){<br />
&nbsp;&nbsp;&nbsp;&nbsp;idx= (i>0) ? (i*3) : 0; //if i>0 then idx=i*3 else i=0<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;public void setName(String name){ this.name = name; }<br />
&nbsp;&nbsp;public String toString() {return &#8220;Name_B: &#8220;+name+&#8221;. Idx: &#8220;+idx;}<br />
}</p>
<p>public class test{</p>
<p>&nbsp;&nbsp;String ArrayObjects[] = {&#8221;A&#8221;,&#8221;B&#8221;,&#8221;C&#8221;};</p>
<p>&nbsp;&nbsp;public test(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;IFigure figObj = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;Constructor constructor[] = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class generic =null;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;int flag=2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;switch(flag){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//The classical way:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A cA = new A();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cA.setName(&#8221;Manolo&#8221;);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//A dynamic way (with same result):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generic = Class.forName(ArrayObjects[0]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructor = generic.getDeclaredConstructors();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;figObj = (IFigure) constructor[1].newInstance(new Object[0]); //equals: new A();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;figObj.setName(&#8221;Manolo&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&#8221;A classical way: \n&#8221;+cA+&#8221;\n&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&#8221;A dynamic way: \n&#8221;+figObj);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 2:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//The classical way:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B cB = new B(23);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cB.setName(&#8221;Manolo&#8221;);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//A dynamic way (with same result):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generic = Class.forName(ArrayObjects[1]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor c = generic.getConstructor(new Class[]{int.class});<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//equals new B(23);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;figObj = (IFigure) c.newInstance(new Object[]{new Integer(23)});<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;figObj.setName(&#8221;Manolo&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&#8221;A classical way: \n&#8221;+cB+&#8221;\n&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&#8221;A dynamic way: \n&#8221;+figObj);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;public static void main(String args[]){<br />
&nbsp;&nbsp;&nbsp;&nbsp;try{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Just instantiating an object from the java.lang.String class and using its *default* constructor.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class i = Class.forName(&#8221;java.lang.String&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String x = (String)i.newInstance();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x += &#8220;some text&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&#8221;First Example: &#8220;+x+&#8221;\n&#8212;&#8212;&#8212;-\n&#8221;);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test t = new test();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}<br />
</em></p></blockquote>
<p>Be mad!</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/20/java-instantiating-an-object-dynamically/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Java Sorting Arrays</title>
		<link>http://www.jjrumi.com/blog/2006/09/16/java-sorting-arrays/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/16/java-sorting-arrays/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 20:41:36 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>Java</category>
	<category>Tips</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/09/16/java-sorting-arrays/</guid>
		<description><![CDATA[The Java API includes a prefabricated method for sorting arrays. According to the official documentation, this method is a tuned quicksort, so we don&#8217;t need to write one.One example:
Long longArray[] = new Long[10];
for(int i=0; i&#60;longArray.length; i++){
&#160;&#160;&#160; //just a random number between 0 - 9
&#160;&#160;&#160; longArray[i] = new Long((new Double(Math.random()*i)).longValue());
}
Arrays.sort(longArray);
for(int i=0; i&#60;longArray.length; i++){
&#160;&#160;&#160;System.out.print(longArray[i].longValue()+&#8221;-&#8221;);


&#8211;> This will output [...]]]></description>
			<content:encoded><![CDATA[<p>The Java API includes a prefabricated method for sorting arrays. According to the official documentation, this method is a tuned quicksort, so we don&#8217;t need to write one.One example:</p>
<blockquote><p><em>Long longArray[] = new Long[10];<br />
for(int i=0; i&lt;longArray.length; i++){<br />
&nbsp;&nbsp;&nbsp; //just a random number between 0 - 9<br />
&nbsp;&nbsp;&nbsp; longArray[i] = new Long((new Double(Math.random()*i)).longValue());<br />
}</p>
<p>Arrays.sort(longArray);</p>
<p>for(int i=0; i&lt;longArray.length; i++){<br />
&nbsp;&nbsp;&nbsp;System.out.print(longArray[i].longValue()+&#8221;-&#8221;);<br />
</em>
</p></blockquote>
<p>&#8211;> This will output a list of numbers sorted in an Ascending way, (like 0,1,2,3,4&#8230;).</p>
<p>If we want to sort it in a reverse order (Descending), we should use: Arrays.sort(longArray,java.util.Collections.reverseOrder());</p>
<p>That simple.</p>
<p>But it isn&#8217;t the most interesting part.<br />
We can sort objects according to some of its attributes.<br />
To sort objects, those objects must implements the Comparable interface. For example:</p>
<blockquote><p>
<em><br />
//Declaring the object<br />
class IndexedFreq implements Comparable{<br />
&nbsp;&nbsp;&nbsp;public int idx;<br />
&nbsp;&nbsp;&nbsp;public int freq;</p>
<p>&nbsp;&nbsp;&nbsp;public IndexedFreq(int idx, int freq){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this idx = idx;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.freq = freq;<br />
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;public int compareTo(Object obj){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IndexedFreq idxfreq2 = (IndexedFreq )obj; //We receive the object to compare<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int f1 = freq; //and we can access to the second object which is compared<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int f2 = idxfreq2.freq</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Here we decide which object must come first<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(f1&lt;f2){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return -1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else if(f2>f1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0; //the freqs are equal<br />
&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p>//Using the object<br />
public class UseIndexedFreq{<br />
&nbsp;&nbsp;&nbsp;public static void main(String args[]){<br />
&nbsp;&nbsp;&nbsp;IndexedFreq idxFreqArray[] = new IndexedFreq[10];<br />
&nbsp;&nbsp;&nbsp;for(int i=0; i&lt;idxFreqArray.length; i++){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idxFreqArray.idx = i;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idxFreqArray.freq = (new Double(Math.random()*i)).intValue();<br />
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;Arrays.sort(idxFreqArray,java.util.Collections.reverseOrder());<br />
}</p>
<p></em>
</p></blockquote>
<p>In the last example I&#8217;ve created an array of IndexedFreq objects, initializing them with an index (idx) and a random frequency (freq)<br/>As shown above, the <em>Arrays.sort(idxFreqArray,java.util.Collections.reverseOrder());</em> method will sort the array, in this case according to the freq value, in a Descending order.</p>
<p>Note that we can do the public int compareTo(Object obj) method as complex as we like. For example we could use a new attribute in the object to define if this object must have a freq=0 so it will be allocated at the begining/end of the array (depending of the order of the sort).
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/16/java-sorting-arrays/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>TFC [technical degree project] - First UML Diagrams [Use Cases]</title>
		<link>http://www.jjrumi.com/blog/2006/09/16/tfc-first-uml-diagrams-use-cases/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/16/tfc-first-uml-diagrams-use-cases/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 16:41:59 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>TFC</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/09/16/tfc-first-uml-diagrams-use-cases/</guid>
		<description><![CDATA[I haven&#8217;t found a way to make UML diagrams with Eclipse yet. Anyway, this is what I&#8217;ve made this afternoon.
The System Use Case:

· SMS Message Control System is the panel where workers will make their job. It will allow: see current messages, write messages, accept &#038; decline incoming messages, etc.
· SMS Bridge will control all [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t found a way to make UML diagrams with Eclipse yet. Anyway, this is what I&#8217;ve made this afternoon.</p>
<p>The System Use Case:<br />
<img title="SMS System Use Case" alt="SMS System Use Case" src="http://jjrumi.com/blog/images/TFC/UseCase_SMSSystem.jpg" /><br/><br />
· <u>SMS Message Control System</u> is the panel where workers will make their job. It will allow: see current messages, write messages, accept &#038; decline incoming messages, etc.<br />
· <u>SMS Bridge</u> will control all System&#8217;s SMS input &#038; output. Here we will deal with TSPs protocols.<br />
· <u>TV Screen Administrator</u> will allow the administrator change the  style of the TV output. Those settings will be readed from our Flash application.<br />
· <u>System Administrator</u> will allow the administrator control the users, a black list and the text responses customers will receive after send a SMS.<br />
· <u>Statistics</u> will use nice graphs to show all kind of statistics. Received SMS, sent SMS, hours of maximum afluence, which TSP is being more profitable, etc.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/16/tfc-first-uml-diagrams-use-cases/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>TFC [technical degree project] - Preface</title>
		<link>http://www.jjrumi.com/blog/2006/09/16/tfc-preface/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/16/tfc-preface/#comments</comments>
		<pubDate>Sat, 16 Sep 2006 10:02:18 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>TFC</category>
		<guid isPermaLink="false">http://www.jjrumi.com/blog/2006/09/16/tfc-preface/</guid>
		<description><![CDATA[Well, I&#8217;m about to start my technical degree project.
We&#8217;re gonna be two people. We both have basic level in the technologies we&#8217;re gonna use (this is a main reason why we wanna do this).
The objective of the project is develop an application to manage the short message (SMS) traffic in a Company, specifically in a [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I&#8217;m about to start my technical degree project.</p>
<p>We&#8217;re gonna be two people. We both have basic level in the technologies we&#8217;re gonna use (this is a main reason why we wanna do this).<br />
The objective of the project is develop an application to manage the <span style="font-style: italic">short message</span> (SMS) traffic in a Company, specifically in a TV environment. That means we&#8217;re gonna need to:</p>
<p style="margin-left: 40px">· show messages in a TV Screen &#8216;nicely&#8217;.<br />
· store it in a DB (a well planned DB).<br />
· provide an interface for the administrators to manage the application, view the state of the traffic, etc.<br />
· control the incoming traffic from the TSPs (Telephony Service Providers&#8230; in Spain, those are mainly MoviStar, Vodafone and Amena).<br />
· and the outgoing traffic (answer the SMSs. This is also called<em> <span style="font-style: italic">premium</span> messages </em>(don&#8217;t ask why :S)).<br />
· provide statistics of the SMS&#8217;s traffic.<br />
· be able to adapt easily to any TSP&#8217;s protocols (every TSP has its protocol, we need to separate clearly the different layers of the application and never compromise our architecture).<br />
· etc&#8230;.</p>
<p>First step will be the the design phase. I wanna find some plugin for Eclipse where I can add UML&#8217;s diagrams.<br />
Technologies We&#8217;re gonna use:</p>
<blockquote><p>· Java</p>
<blockquote><p>· Servlets: The Model and Controller side.</p>
<p>· JSP: The View side (for the admin interfaces).</p>
<p>· AJAX???</p></blockquote>
<p>· Flash: output on the TV Screen<br />
· MySQL: DataBase</p></blockquote>
<p>That&#8217;s all for today.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/16/tfc-preface/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Start just because and finish don&#8217;t know when.</title>
		<link>http://www.jjrumi.com/blog/2006/09/14/hello-world/</link>
		<comments>http://www.jjrumi.com/blog/2006/09/14/hello-world/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 15:38:07 +0000</pubDate>
		<dc:creator>jjrumi</dc:creator>
		
	<category>Digressing</category>
		<guid isPermaLink="false"></guid>
		<description><![CDATA[Hi there, my name is JuanLu.
It has been a long time since I wanted to create my own blog.
Lack of free time, not knowing what exactly I could write&#8230; but now I have a perfect excuse. My degree project, I want to practice my English and well&#8230; I have a day of leisure and I [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there, my name is JuanLu.<br />
It has been a long time since I wanted to create my own blog.<br />
Lack of free time, not knowing what exactly I could write&#8230; but now I have a perfect excuse. My degree project, I want to practice my English and well&#8230; I have a day of leisure and I build a blog, <img src='http://www.jjrumi.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>I hope it&#8217;s gonna last.</p>
<p>Show time.<br />
&#8212;&#8212;&#8212;&#8212;<br />
Post Scriptum: By the way, &#8216;Tre e mezzo&#8217; means &#8216;Three and (a) half&#8217;. It&#8217;s Italian. I like to look at the world from a half way. Neither black nor white.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.jjrumi.com/blog/2006/09/14/hello-world/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
