<?xml version="1.0"?>
<!-- name="generator" content="blojsom v3.1" -->
<rdf:RDF xmlns:wfw="http://wellformedweb.org/CommentAPI/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns="http://purl.org/rss/1.0/">

	<channel rdf:about="http://blog.marcnuri.com/blog/default">
		<title>Marc Nuri&#39;s Happy Coding Blog</title>
		<link>http://blog.marcnuri.com/blog/default/</link>
		<description>Code snippets, tips, tricks and problems for everyday coders.</description>
		<dc:publisher>Marc Nuri San Félix</dc:publisher>
		<dc:creator>marc@marcnuri.com</dc:creator>
		<dc:date>2008-11-18T09:53:18+01:00</dc:date>
		<dc:language>en</dc:language>

        <items>
        <rdf:Seq>
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2008/11/18/BeansBinding-Performance-Issue-37" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/11/12/Reading-UTF-8-encoded-documents-in-java-1-5" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/09/13/Viewing-and-storing-images-from-an-IP-Camera" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/08/22/java-lang-OutOfMemoryError-PermGen-space-More-memory-for-Tomcat-under-windows" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/08/03/Updated-Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/07/16/Getting-started-with-JasperReports-Printing-reports-from-your-java-app-Part-III" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/06/07/Replacing-Apostrophes-from-Strings-Cleaning-String-to-pass-them-as-SQL-statements" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/06/06/Detecting-Tab-Key-Pressed-Event-in-JTextField-s-Event-VK-TAB-KeyPressed" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/05/30/Dynamic-icons-for-your-JComponents-Create-an-icon-JButton-with-dynamic-icons" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/05/23/JTable-detecting-selection-changes-ListSelectionListener-Selection-Changed-Event" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/05/21/SimpleDateFormat-to-check-user-date-input-parsing-String-to-dates-in-java" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/05/07/Numbers-to-Strings-with-custom-symbols-DecimalFormat-DecimalFormatSymbols" />
                                <rdf:li rdf:resource="http://blog.marcnuri.com/blog/default/2007/04/18/Java-recursive-functions-explained-Using-recursion-to-sum-an-array-of-numbers" />
                </rdf:Seq>
        </items>
    </channel>

            <item rdf:about="http://blog.marcnuri.com/blog/default/2008/11/18/BeansBinding-Performance-Issue-37">
	    <title>BeansBinding Performance (Issue 37)</title>
	    <link>http://blog.marcnuri.com/blog/default/2008/11/18/BeansBinding-Performance-Issue-37</link>
        <description>&lt;p&gt;Since the release of &lt;a href=&quot;http://www.netbeans.org&quot;&gt;NetBeans&lt;/a&gt; 6.0, &lt;a href=&quot;https://beansbinding.dev.java.net/&quot;&gt;BeansBinding (JSR 295)&lt;/a&gt; framework popularity has increased. Personally I&#39;m using it now in all my projects. Ease of development and the increase of productivity are worth it. The counterpart is that this project looks dead and hasn&#39;t been updated for more than a year now. Even more, recent news about Swing core is not very &lt;a href=&quot;http://www.pushing-pixels.org/?p=758&quot;&gt;encouraging&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In my opinion I believe that Sun&#39;s budget is very limited and their recent &lt;a href=&quot;http://www.javafx.com&quot;&gt;javaFx&lt;/a&gt; has consumed all their resources in the past year. Bearing in mind that BeansBinding is now included in netbeans and that javaFx is based in swing, I don&#39;t think that neither of the projects is going to be abandoned.&lt;/p&gt;
&lt;p&gt;Getting into the subject, BeansBinding has not been updated for a while now, and has some bugs that are really annoying. If you use beans binding to bind a form with more than 20 fields you&#39;ll notice how the form takes a lot to load. If you profile your application, you&#39;ll quickly notice that the bottleneck is in the statement bindingGroup.bind() in the initComponents() section of your code (if you are using Netbeans + matisse). Taking a deeper look with the netbeans profiler tool we get to our point. If you examine carefully BeanPropery or ElPropery class, the method getBeanInfo(Object object) is calling  Introspector.getBeanInfo(object.getClass(), Introspector.IGNORE_ALL_BEANINFO); which takes a lot of time. I Googled to see if I could get any clue about what was happening and if someone else was experiencing the same problem. I found a 2 mail &lt;a href=&quot;http://markmail.org/message/lx4bmanxhehxohqp#query:beansbinding%20getbeaninfo%20Introspector+page:1+mid:meoioz6c52dcbued+state:results&quot;&gt;message  thread&lt;/a&gt;. Not very popular for such a big performance problem. The thread informs of the created Issue (&lt;a href=&quot;https://beansbinding.dev.java.net/issues/show_bug.cgi?id=37&quot;&gt;Issue 37&lt;/a&gt;) the and suggest a possible solution using USE_ALL_BEANINFO (which by the way is the default flag used if you call the Introspector.getBeanInfo(Class class) directly).&lt;/p&gt;
&lt;p&gt;The slow dialog opening is really pissing me, so I&#39;ve implemented a solution. Your first approach can be by getting the source code and replacing the code fragment you need and then recompile the library. There is a great tutorial (&lt;a href=&quot;http://www.javaworld.com/javaworld/jw-05-2004/jw-0510-patch.html&quot;&gt;Hacking Java Libraries&lt;/a&gt;) which teaches you how to do this if you don&#39;t know how to do it by yourself. The article is an exception of &amp;quot;&lt;a href=&quot;http://safari.oreilly.com/0672326388&quot;&gt;Covert Java&lt;/a&gt;&amp;quot; by Alex Kalinovsky (Sams Publishing, May 2004) (recommended reading).&lt;/p&gt;
&lt;p&gt;I don&#39;t really like the approach above. With these technique you can&#39;t keep track of the changes you&#39;ve made and further updates of the library will need to be modified and recompiled again (until the bug is corrected). I prefer to manipulate the bytecode at runtime to reflect the changes I need (BCEL). For this purpose I&#39;m going to use the &lt;a href=&quot;http://www.csg.is.titech.ac.jp/~chiba/javassist/&quot;&gt;javassist&lt;/a&gt; library which is very light and straightforward. In the next code fragment you have the code needed to get the modification working.&lt;/p&gt;
&lt;pre style=&quot;color:#000000;background:#EEEEEE;&quot;&gt;
try {
            ClassPool cp = ClassPool.getDefault();
            CtClass cc = cp.get(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;org.jdesktop.beansbinding.ELProperty&quot;&lt;/span&gt;);
            CtMethod m = cc.getDeclaredMethod(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;getBeanInfo&quot;&lt;/span&gt;);
            m.setBody(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;{&quot;&lt;/span&gt;+
                    &lt;span style=&quot;color:#3f7f59; &quot;&gt;//&quot;assert $1 != null;&quot; +&lt;/span&gt;
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;try {&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;return java.beans.Introspector.getBeanInfo($1.getClass());&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;} catch (java.beans.IntrospectionException ie) {&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;throw new org.jdesktop.beansbinding.PropertyResolutionException(&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;Exception while introspecting&lt;/span&gt; &lt;span style=&quot;color:#2a00ff; &quot;&gt;\&quot;&lt;/span&gt; &lt;span style=&quot;color:#2a00ff; &quot;&gt;+ $1.getClass().getName(), ie);&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;} }&quot;&lt;/span&gt;);
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;Class&lt;/span&gt; c = cc.toClass();
            cc = cp.get(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;org.jdesktop.beansbinding.BeanProperty&quot;&lt;/span&gt;);
            m = cc.getDeclaredMethod(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;getBeanInfo&quot;&lt;/span&gt;);
            m.setBody(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;{&quot;&lt;/span&gt;+
                    &lt;span style=&quot;color:#3f7f59; &quot;&gt;//&quot;assert $1 != null;&quot; +&lt;/span&gt;
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;try {&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;return java.beans.Introspector.getBeanInfo($1.getClass());&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;} catch (java.beans.IntrospectionException ie) {&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;throw new org.jdesktop.beansbinding.PropertyResolutionException(&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;Exception while introspecting&lt;/span&gt; &lt;span style=&quot;color:#2a00ff; &quot;&gt;\&quot;&lt;/span&gt; &lt;span style=&quot;color:#2a00ff; &quot;&gt;+ $1.getClass().getName(), ie);&quot;&lt;/span&gt; +
                    &lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;} }&quot;&lt;/span&gt;);
            c = cc.toClass();
        } catch (NotFoundException ex) {
            ex.printStackTrace();
        } catch (CannotCompileException ex) {
            ex.printStackTrace();
        }
&lt;/pre&gt;
&lt;p&gt;What the above code does is replace  the method body of getBeanInfo in ElPropery and BeanPropery with the modified code that suits our needs. In this case, instead of calling Introspector.getBeaninfo(Class class, int flag) it calls Introspector.getBeanInfo(Class class) which by default uses gets the cached information improving performance. For all of this to work its very important to run this code before any other code which uses the beansbinding library is called. If you can&#39;t do that, read the javassist &lt;a href=&quot;http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial.html&quot;&gt;tutorial&lt;/a&gt; to build a loader or use &lt;a href=&quot;http://www.csg.is.titech.ac.jp/~chiba/javassist/html/javassist/util/HotSwapper.html&quot;&gt;HotSwapper&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I don&#39;t know why &lt;a href=&quot;http://weblogs.java.net/blog/shan_man/&quot;&gt;Shannon&lt;/a&gt; decided to use the  Introspector.IGNORE_ALL_BEANINFO flag in the first place, maybe there&#39;s a good reason. I can&#39;t really think why we shouldn&#39;t use the cached info, there&#39;s no reason why a bean should change its structure during runtime (Unless someone is using dynamic bytecode engineering BCEL).&lt;/p&gt;
&lt;p&gt;I hope this code helps you. Please if you have any comments, suggestions or improvements, please post them. Thank you..&lt;/p&gt;
</description>
	    <dc:date>2008-11-18T09:53:18+01:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2008/11/18/BeansBinding-Performance-Issue-37</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2008/11/18/BeansBinding-Performance-Issue-37?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/11/12/Reading-UTF-8-encoded-documents-in-java-1-5">
	    <title>Reading UTF-8 encoded documents in java</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/11/12/Reading-UTF-8-encoded-documents-in-java-1-5</link>
        <description>&lt;p&gt;Reading the contents of a file in Java is a very straight forward operation. The &lt;a href=&quot;http://java.sun.com/docs/books/tutorial/essential/io/streams.html&quot;&gt;java tutoria&lt;/a&gt;l explains completely how you can find your way to read different types of streams.&lt;/p&gt;
&lt;p&gt;However when you read an UTF-8 encoded file your fight will start. Most of the UTF-8 and UTF-16 encoded files contain a character at the beginning called BOM (byte-order mark). The BOM consists of a character  (U+FEFF) at the beginning of the stream used to define the byte order and the encoding of the stream. UTF encoded files may or may not containg the BOM.&lt;/p&gt;
&lt;p&gt;The problem with Java comes when you read a unicode file with a byte-order mark. Java doesn&#39;t detect the BOM by itself so when you represent the data contained in the file, the BOM contaminates it. There is an open &lt;a href=&quot;http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058&quot;&gt;BUG&lt;/a&gt; in sun&#39;s bug database with the explanation and some workaround users have made.&lt;/p&gt;
&lt;p&gt;The solution is as simple as as reading the first bytes of an UTF encoded file and check if those a are a BOM or not. If they are, just remove them and continue reading the file. This is not so complicated because there are not so many types of BOM (5) and they are easy to identify.&lt;/p&gt;
&lt;table border=&quot;0&quot; style=&quot;padding:3px;margin:3px;border:1px solid black;&quot; width=&quot;300&quot; cellpadding=&quot;1&quot; align=&quot;center&quot;&gt;
    &lt;tr&gt;
        &lt;th width=&quot;50%&quot;&gt;Bytes&lt;/th&gt;
        &lt;th width=&quot;50%&quot;&gt;Encoding Form&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td width=&quot;50%&quot;&gt;00 00 FE FF&lt;/td&gt;
        &lt;td width=&quot;50%&quot;&gt;UTF-32, big-endian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td width=&quot;50%&quot;&gt;FF FE 00 00&lt;/td&gt;
        &lt;td width=&quot;50%&quot;&gt;UTF-32, little-endian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td width=&quot;50%&quot;&gt;FE FF&lt;/td&gt;
        &lt;td width=&quot;50%&quot;&gt;UTF-16, big-endian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td width=&quot;50%&quot;&gt;FF FE&lt;/td&gt;
        &lt;td width=&quot;50%&quot;&gt;UTF-16, little-endian&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td width=&quot;50%&quot;&gt;EF BB BF&lt;/td&gt;
        &lt;td width=&quot;50%&quot;&gt;UTF-8&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;When one of this characters is identified you just have to remove it so your program can interpret the file as it should be. A user has contributed with &lt;a href=&quot;http://koti.mbnet.fi/akini/java/unicodereader/&quot;&gt;two helper classes&lt;/a&gt; that can do the job for you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Related links:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.unicode.org/unicode/faq/utf_bom.html#22&quot;&gt;Unicode FAQ&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Byte_Order_Mark&quot;&gt;BOM at wikipedia&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://koti.mbnet.fi/akini/java/unicodereader/&quot;&gt;Helper Classes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
	    <dc:date>2007-11-12T09:55:34+01:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/11/12/Reading-UTF-8-encoded-documents-in-java-1-5</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/11/12/Reading-UTF-8-encoded-documents-in-java-1-5?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/09/13/Viewing-and-storing-images-from-an-IP-Camera">
	    <title>Viewing and storing images from an IP Camera</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/09/13/Viewing-and-storing-images-from-an-IP-Camera</link>
        <description>&lt;p&gt;So you bought an IP camera and would like to store/see images from the camera using java. Recently I bought a couple of IP Cameras for testing purposes. I noticed that each IP camera has different surveillance tools and web interfaces. But most of them have in common that you can access the actual picture by entering an url in your browser.&lt;/p&gt;
&lt;p&gt;In this post I&#39;ll show you how to see that image and store it using a very simple jav application. The camera I&#39;ll use for the test is a LinkSys &lt;a href=&quot;http://www.linksys.com/servlet/Satellite?c=L_Product_C2&amp;amp;childpagename=US%2FLayout&amp;amp;cid=1143837459487&amp;amp;pagename=Linksys%2FCommon%2FVisitorWrapper&quot;&gt;WVC200&lt;/a&gt; &amp;quot;Wireless PTZ Internet Camera with Audio&amp;quot;. This is the cheapest wireless IPcam I found with at least&lt;br /&gt;some decent features.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img height=&quot;203&quot; style=&quot;margin: 5px&quot; alt=&quot;WVC200&quot; src=&quot;http://www.netdigital.biz/ProductImages/WVC200.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This camera has a nice web interface but for visualization purposes you will need to be sitting in front of a windows desktop. This camera as many others uses an activeX control to show/control the image. The thing is that LinkSys is kind enough to offer the camera&#39;s Firmware &lt;a href=&quot;http://www.linksys.com/servlet/Satellite?c=L_CASupport_C1&amp;amp;childpagename=US%2FLayout&amp;amp;cid=1169671246380&amp;amp;pagename=Linksys%2FCommon%2FVisitorWrapper&amp;amp;lid=4638012899B01#WVC200&quot;&gt;source code&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you analyze the source code you can find some clues to get the URL where the static image is served (there&#39;s an url for video too ASF format, with some time you can develop an app to store and play the video). In the case of this camera is &amp;quot;http://CAMERAIP/img/snapshot.cgi?size=640x480&amp;quot;.&lt;/p&gt;
&lt;p&gt;With this information we can build an application to grab the image and show/store the image. If you have another type of camera, you can adapt the program by specifying the url.&lt;/p&gt;
&lt;pre id=&#39;code&#39; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;&gt;try {
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Build a new URL specifying the path to where the image&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;    * is served */&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;URL&lt;/span&gt; url = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;URL&lt;/span&gt; (&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;http://192.168.10.80/img/snapshot.cgi?size=640x480&quot;&lt;/span&gt;);
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/*String with the user and password to access the camera interface&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;    *(userName and password that you would enter in the browser*/&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt; userPassword =  &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;USER:PASSWORD&quot;&lt;/span&gt;;
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* We must encode with Base64 to supply it with the header.*/&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt; encoding = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; Base64Encoder(userPassword).processString();
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/*Open the connection*/&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;URLConnection&lt;/span&gt; uc = url.openConnection();
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Specify the authorization*/&lt;/span&gt;
    uc.setRequestProperty (&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Authorization&quot;&lt;/span&gt;, &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Basic &quot;&lt;/span&gt; + encoding);
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Load a copy of the image into memmory */&lt;/span&gt;
    BufferedImage img = ImageIO.read(uc.getInputStream());
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Show the image in a JLabel */&lt;/span&gt;
    jLImagen.setIcon(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; ImageIcon(img));
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Store the image in the specified path*/&lt;/span&gt;
    ImageIO.write(img, &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;jpg&quot;&lt;/span&gt;, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;File&lt;/span&gt;(&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;pathToFile&quot;&lt;/span&gt;));
} catch (MalformedURLException ex) {
    ex.printStackTrace();
} catch (IOException ex) {
    ex.printStackTrace();
}
&lt;/pre&gt;
&lt;p&gt;Extending this simple application or adding some functionality can bring a very good surveillance application.
If you analyze most commercial surveillance applications to use with different ipCameras you&#39;ll notice
that although they are very expensive the core of the application is similar to the 10 lines of code above.&lt;/p&gt;
</description>
	    <dc:date>2007-09-13T12:19:37+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/09/13/Viewing-and-storing-images-from-an-IP-Camera</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/09/13/Viewing-and-storing-images-from-an-IP-Camera?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/08/22/java-lang-OutOfMemoryError-PermGen-space-More-memory-for-Tomcat-under-windows">
	    <title>java.lang.OutOfMemoryError: PermGen space // More memory for Tomcat under windows</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/08/22/java-lang-OutOfMemoryError-PermGen-space-More-memory-for-Tomcat-under-windows</link>
        <description>&lt;p&gt;In many cases, web applications give OutOfMemoryError when their threads require high levels of  memory. Image manipulation or intensive database use or calculation can lead to this very common problem.&lt;/p&gt;
&lt;p&gt;Normally when you get an OutOfMemory error in a desktop application, you can solve this problem by specifying the java commands -Xms*** (initial Java heap size) and -Xmx*** (maximum Java heap size) when running your program.&lt;/p&gt;
&lt;p&gt;To solve this issue in tomcat, you must specify these options in the tomcat startup command / script / batch. In windows tomcat is installed as a service. Tomcat provides a configuration tool to set up these and other parameters. you can find it in (Start-&amp;gt;Programs-&amp;gt;Apache Tomcat-&amp;gt;Configure Tomcat) or by running (.\bin\tomcat5w.exe&amp;quot; //EN//Tomcat5).&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;margin: 5px&quot; alt=&quot;Tomcat Properties&quot; src=&quot;http://farm2.static.flickr.com/1354/1202329417_8f1e17a1a0.jpg?v=0&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Under the &amp;quot;Java&amp;quot; tab you can find two options:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Initial memory pool: This corresponds to -Xms, you can specify the size in Mb.&lt;/li&gt;
    &lt;li&gt;Maximum memory pool: This corresponds to -Xmx, you can specify the size in Mb.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now you can specify a higher maximum memory so that Tomcat doesn&#39;t get the OutOfMemoryError. Remember to take in consideration your hardware capabilities.&lt;/p&gt;
</description>
	    <dc:date>2007-08-22T15:55:03+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Apache+Tomcat/2007/08/22/java-lang-OutOfMemoryError-PermGen-space-More-memory-for-Tomcat-under-windows</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/08/22/java-lang-OutOfMemoryError-PermGen-space-More-memory-for-Tomcat-under-windows?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/08/03/Updated-Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer">
	    <title>Updated: Displaying a jTable inside another jTable // JTable cellRenderer</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/08/03/Updated-Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer</link>
        <description>&lt;p&gt;After some users asking for answers in my &lt;a href=&quot;http://blog.marcnuri.com/blog/default/2007/04/04/Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer&quot;&gt;past post&lt;/a&gt;, I updated the code of the embedded JTable to make it less buggy and more stable.&lt;/p&gt;
&lt;p&gt;This is the &quot;new&quot; code:&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;/* We initialize the Objects where we&amp;#39;ll store our data */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;/* First an array Object which will be our main table */&lt;br /&gt;&lt;/span&gt; Object[][] data = null;&lt;br /&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;/* We create an Array String to hold the name of the main table columns&lt;/span&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;In this example case we are going to store a contact name,&lt;/span&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;his email address(es) and his phone numer(s)&lt;/span&gt;
&lt;span style=&quot;color: #3f7f59&quot;&gt;We&amp;#39;re also going to store the creation date.*/&lt;br /&gt;&lt;/span&gt;
String[] columns = {&lt;span style=&quot;color: #2a00ff&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #2a00ff&quot;&gt;&amp;quot;E-Mail&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #2a00ff&quot;&gt;&amp;quot;Phone&amp;quot;&lt;/span&gt;,&lt;span style=&quot;color: #2a00ff&quot;&gt;&amp;quot;Creation Date&amp;quot;&lt;/span&gt;};&lt;br /&gt;&lt;/pre&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;&lt;span style=&#39;color:#3f7f59; &#39;&gt;/* First thing is  to populate our data object with some example values*/&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; void populateData(){
        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Two contacts*/&lt;/span&gt;
        data = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt;[3][columns.length];
        data[0][0] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Peter&quot;&lt;/span&gt;;
        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt;[] emails = {&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;peter@yahoo.com&quot;&lt;/span&gt;, &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;strange@name.com&quot;&lt;/span&gt;};
        data[0][1] = emails;
        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt;[] phones = {&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;555 35 25 65&quot;&lt;/span&gt; , &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;555 35 24 63&quot;&lt;/span&gt;};
        data[0][2] = phones;
        data[0][3] = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Date&lt;/span&gt;();
        data[1][0] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Jackson&quot;&lt;/span&gt;;
        data[1][1] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Jack@hotmail.com&quot;&lt;/span&gt;;
        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt;[] phones2 = {&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;555 35 24 33&quot;&lt;/span&gt; , &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;555 11 88 88&quot;&lt;/span&gt;, &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;332 55 25 34&quot;&lt;/span&gt;};
        data[1][2] = phones2;
        data[1][3] = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Date&lt;/span&gt;();
        data[2][0] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;Robert&quot;&lt;/span&gt;;
        data[2][1] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;rob@hotmail.com&quot;&lt;/span&gt;;
        data[2][2] = &lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;555 28 95 81&quot;&lt;/span&gt;;
        data[2][3] = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Date&lt;/span&gt;();
        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* AS you can see, we&#39;ve stored two contacts one with two e-mail&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;         accounts and two phone numbers, and another member with three phone&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;         numbers*/&lt;/span&gt;
    }
    &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Next we create our table models */&lt;/span&gt;
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; void createModel(){
        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* First we create the main model&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;         We overide the AbstractTableModel necessary methods*/&lt;/span&gt;
        AbstractTableModel  modelo = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; AbstractTableModel() {
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;String&lt;/span&gt; getColumnName(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col) {
                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; columns[col].toString();
            }
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Class&lt;/span&gt; getColumnClass(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col) {
              &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;if&lt;/span&gt;(getRowCount() &amp;lt;1)&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;null&lt;/span&gt;;
            &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; data[0][col].getClass();
          }
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; getRowCount() { &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; data.length; }
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; getColumnCount() { &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; columns.length;}
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt; getValueAt(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; row, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col) {
                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; data[row][col];
          }
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;boolean&lt;/span&gt; isCellEditable(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; row, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col){ &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;true&lt;/span&gt;; }
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;void&lt;/span&gt; setValueAt(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt; value, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; row, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col) {
            data[row][col] =  value;
            fireTableCellUpdated(row, col);
          }};
          &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* We apply the model to the main jTable */&lt;/span&gt;
          jTableData.setModel(modelo);
          &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* We create a cell Renderer to display the data of the multivalue&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;           fields*/&lt;/span&gt;
          TableCellRenderer jTableCellRenderer = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; TableCellRenderer() {
              &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Magic Happens */&lt;/span&gt;
              &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Component&lt;/span&gt; getTableCellRendererComponent(JTable table,
                      &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt; value, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;boolean&lt;/span&gt; isSelected, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;boolean&lt;/span&gt; hasFocus,
                      &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; row, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; column) {
                  &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* If what we&#39;re displaying isn&#39;t an array of values we&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;                   return the normal renderer*/&lt;/span&gt;
                    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;if&lt;/span&gt;(!value.getClass().isArray()){
                       &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; table.getDefaultRenderer( 
                               value.getClass()).getTableCellRendererComponent(
                               table, value, isSelected, hasFocus,row, column);
                    }
                    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;else&lt;/span&gt;{
                        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;final&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt;[] passed = (&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt;[])value;             
                        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* We create the table that will hold the multivalue&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;                         *fields and that will be embedded in the main table */&lt;/span&gt;
                        JTable embedded = &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; JTable(
                            &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; AbstractTableModel() {
                                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; getColumnCount() {
                                    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; 1;
                                }
                                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; getRowCount() {
                                    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; passed.length;
                                }
                                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;Object&lt;/span&gt; getValueAt(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; rowIndex, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; columnIndex) {
                                    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; passed[rowIndex];
                                }
                                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;boolean&lt;/span&gt; isCellEditable(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; row, &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; col){ &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;true&lt;/span&gt;; }
                        });
                         
                        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;if&lt;/span&gt;(isSelected){
                            embedded.setBackground(jTableData.getSelectionBackground());
                            embedded.setForeground(jTableData.getSelectionForeground());
                        }
                        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;if&lt;/span&gt;(hasFocus){
                            embedded.setRowSelectionInterval(0,1);
                        }
                        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* If this is what you plan to enable mouseClick detection,&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;                            in your table, IT WONT WORK. Have a look at TableCellEditor.*/&lt;/span&gt;
                        embedded.addMouseListener(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;new&lt;/span&gt; MouseAdapter() {
                            &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;void&lt;/span&gt; mouseClicked(java.awt.event.&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;MouseEvent&lt;/span&gt; evt) {
                                &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;System&lt;/span&gt;.out.println(&lt;span style=&#39;color:#2a00ff; &#39;&gt;&quot;PEPE&quot;&lt;/span&gt;);
                            }
                        });
                        
                        setPreferredSize(embedded.getPreferredSize());
                         &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;if&lt;/span&gt;(getPreferredSize().height != table.getRowHeight(row))
                            {
                                table.setRowHeight(row, getPreferredSize().height);
                            }

                        &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;return&lt;/span&gt; embedded;
                    }
              }
          };
          &lt;span style=&#39;color:#3f7f59; &#39;&gt;/* Finally we apply the new cellRenderer to the whole table */&lt;/span&gt;
          TableColumnModel tcm = jTableData.getColumnModel();
          &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;for&lt;/span&gt;(&lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;int&lt;/span&gt; it = 0; it &amp;lt; tcm.getColumnCount(); it++){
              tcm.getColumn(it).setCellRenderer(jTableCellRenderer);
             &lt;span style=&#39;color:#3f7f59; &#39;&gt;// tcm.getColumn(it).setCellEditor(jTableCellEditor);&lt;/span&gt;
          }
          &lt;span style=&#39;color:#3f7f59; &#39;&gt;/*Note: if we need to edit the values inside the embedded jtable&lt;/span&gt;
&lt;span style=&#39;color:#3f7f59; &#39;&gt;           * we will need to create a TableCellEditor too. */&lt;/span&gt;
          
    }
&lt;/pre&gt;
 &lt;p&gt;&lt;img style=&quot;margin: 5px&quot; src=&quot;http://blog.marcnuri.com/resources/default/multivaluejtable.jpg&quot; alt=&quot;JTable with another embedded JTable&quot; /&gt;&lt;/p&gt; &lt;p&gt;In the above image you can see the result.&lt;/p&gt;
</description>
	    <dc:date>2007-08-03T08:41:10+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/08/03/Updated-Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/08/03/Updated-Displaying-a-jTable-inside-another-jTable-JTable-cellRenderer?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/07/16/Getting-started-with-JasperReports-Printing-reports-from-your-java-app-Part-III">
	    <title>Getting started with JasperReports // Printing reports from your java app (Part III)</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/07/16/Getting-started-with-JasperReports-Printing-reports-from-your-java-app-Part-III</link>
        <description>&lt;p&gt;In the past 2 entries (&lt;a href=&quot;http://blog.marcnuri.com/blog/default/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I&quot;&gt;Part I&lt;/a&gt; and &lt;a href=&quot;http://blog.marcnuri.com/blog/default/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II&quot;&gt;Part II&lt;/a&gt;) we learnt how to develop a basic report and how to fill it with data from a database with a jdbc connector. Now we will learn how to call a report from within a Java application and how to set some basic parameters.&lt;/p&gt;
&lt;p&gt;The most important thing when running your reports from within a java application is to have all the necessary jar libraries available from your classpath. The basic ones for running the sample report will be commons-logging-*.jar, commons-collections-*.jar, jasperrerports-*.jar and yourJDBCconnector.jar. All of them (except the jdbc connector) can be found in the iReport ./lib directory.&lt;/p&gt;
&lt;p&gt;Next thing you&#39;ll need is a compiled version of your report. This you can find in the same folder you saved your report when you developed it in iReport. It will have the same name as the report source but the extension will be .jasper.&lt;/p&gt;
&lt;p&gt;Now we are ready to call our report from Java. The most important class now is &lt;a href=&quot;http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/class-use/JasperPrint.html&quot;&gt;JasperPrint&lt;/a&gt;. The basics for this class are to specify a report and a datasource to fill it. In the following lines you&#39;ll find the code to run our report. The example simply creates a postgresql datasource and gives the path to the compiled jasper file. Then with some simple parameters it specifies the number of copies and tells the program to print the report.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap; white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
try {
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Number of copies to print */&lt;/span&gt;
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;int&lt;/span&gt; numberOfCopies = 1;
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Create the jdbc datasource&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;            * you&#39;ll have to change this code to your database vendor specific&lt;/span&gt; 
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;            * jdbc */&lt;/span&gt;
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;Class&lt;/span&gt;.forName(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;org.postgresql.Driver&quot;&lt;/span&gt;);
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;Connection&lt;/span&gt; conn = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;DriverManager&lt;/span&gt;.getConnection(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;jdbc:postgresql://localhost:5432/postgres?user=postgres&amp;amp;password=PASSWORD1&quot;&lt;/span&gt;);
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;ResultSet&lt;/span&gt; rs = conn.createStatement().executeQuery(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;SELECT * FROM pg_tables ORDER BY 1&quot;&lt;/span&gt;);
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Create a Jasper DataSource */&lt;/span&gt;
            JRDataSource ds = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; JRResultSetDataSource(rs);
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Fill the report with the new datasource */&lt;/span&gt;
            JasperPrint print = JasperFillManager.fillReport(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;C:&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;Documents and Settings&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;Administrador&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;Mis documentos&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;test.jasper&quot;&lt;/span&gt;, &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; HashMap(), 
                ds);
            PrintRequestAttributeSet printRequestAttributeSet = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; HashPrintRequestAttributeSet();
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Set the number of copies */&lt;/span&gt;
            printRequestAttributeSet.add(&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; Copies(numberOfCopies));
            printRequestAttributeSet.add(&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; JobName(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;Job Name&quot;&lt;/span&gt;, &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;));
            
            net.sf.jasperreports.engine.export.JRPrintServiceExporter exporter;
            exporter = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; net.sf.jasperreports.engine.export.JRPrintServiceExporter();  
            exporter.setParameter( JRExporterParameter.JASPER_PRINT, print);
            exporter.setParameter( JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
            exporter.setParameter( JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
            exporter.setParameter( JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
            exporter.exportReport();
            rs.close();
            conn.close();
            rs = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
            conn = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
            exporter = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
            print =&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
            printRequestAttributeSet = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (JRException ex) {
            ex.printStackTrace();
        }
&lt;/pre&gt;
</description>
	    <dc:date>2007-07-16T07:59:11+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/07/16/Getting-started-with-JasperReports-Printing-reports-from-your-java-app-Part-III</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/07/16/Getting-started-with-JasperReports-Printing-reports-from-your-java-app-Part-III?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II">
	    <title>Getting started with JasperReports // JDBC connections (Part II)</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II</link>
        <description>&lt;p&gt;This is the second part of a series of articles to get people started with JasperReports. In the second part I&#39;ll explain how to access your database to run simple queries and show them in a very simple report created with iReport.&lt;/p&gt;
&lt;p&gt;The first thing we need to do to get moving is to have iReport ready. So if you haven&#39;t got it installed &lt;a href=&quot;http://www.dzone.com/r/getting_started_with_jasperreports_reporting_in_j.html&quot;&gt;do so&lt;/a&gt;. Next step is to have the database driver in your iReport library folder. This means that you will need a jdbc jar packaged driver copied to the ./lib/ directory of iReport&#39;s base folder. This step is really important not doing so will not allow you to connect to the database. Most databases provide their own jdbc driver, there are &lt;a href=&quot;http://java.sun.com/docs/books/tutorial/jdbc/&quot;&gt;many&lt;/a&gt; tutorials and references that speak about jdbc.&lt;/p&gt;
&lt;p&gt;Now is the time to configure access to your database. You have to go to the menu &amp;quot;Data -&amp;gt; Connections/Datasources&amp;quot;. Then you must click the &amp;quot;New&amp;quot; button.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img style=&quot;margin: 5px&quot; alt=&quot;iReport Connection Dialog&quot; src=&quot;http://farm2.static.flickr.com/1388/657817884_7c3dd6c5ef.jpg?v=0&quot; /&gt;&lt;/p&gt;
&lt;p&gt;When you get this dialog, the first thing to do is to give a name to the connection &amp;quot;Name&amp;quot;. Next is to specify the driver to connect to your database.Then you&#39;ll have to modify the JDBC URL to access your database (You can use the wizard to do this too). Finally you must specify the username and password with permission to get access to the database. It&#39;s convenient to test the connection before saving.&lt;/p&gt;
&lt;p&gt;With your connection ready, is time to query the database. In my case I will be using PostgreSQL and I will build a simple query to get the database table names. For this you must go to the menu &amp;quot;Data -&amp;gt; Report Query&amp;quot;.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img style=&quot;margin: 5px&quot; alt=&quot;iReport Data -&gt; Report Query&quot; src=&quot;http://farm2.static.flickr.com/1011/657880930_0e37041475.jpg?v=0&quot; /&gt;&lt;/p&gt;
&lt;p&gt;When you insert your SQL query, in my case &amp;quot;SELECT * FROM pg_tables ORDER BY 1&amp;quot; iReport automatically gets the metadata for your query and stores them as report fields so you can use them during the development of your report.&lt;/p&gt;
&lt;p&gt;Finally with the retrieved report fields we can now create our report. This is the result:&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img style=&quot;margin: 5px&quot; alt=&quot;iReport final Result&quot; src=&quot;http://farm2.static.flickr.com/1048/657087641_096c8ad2b0.jpg?v=0&quot; /&gt;&lt;/p&gt;
</description>
	    <dc:date>2007-06-29T09:05:41+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/06/29/Getting-started-with-JasperReports-JDBC-connections-Part-II?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I">
	    <title>Getting started with JasperReports // Reporting in Java (Part I)</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I</link>
        <description>&lt;p&gt;This is the first of a series of articles to get you started with JasperReports. In first place, JasperReports is one of Java&#39;s reporting engines. It&#39;s very powerful and has lots of features that makes it comparable to commercial reporting solutions such as Crystal Reports.&lt;/p&gt;
&lt;p&gt;The first thing you need to do to start using this great peace of software is go to the &lt;a href=&quot;http://www.jasperforge.org/sf/projects/jasperreports&quot;&gt;project page&lt;/a&gt; and &lt;a href=&quot;http://www.jasperforge.org/index.php?option=com_content&amp;task=section&amp;id=16&amp;Itemid=277&quot;&gt;download&lt;/a&gt; it (wait). In the project page there is some &lt;a href=&quot;http://www.jasperforge.org/index.php?option=com_docman&amp;task=cat_view&amp;gid=19&amp;Itemid=248&quot;&gt;documentation&lt;/a&gt; that will help you getting started.&lt;/p&gt;
&lt;p&gt;You must know that JasperReports is a reporting engine that integrates many capabilities. Reports are developed using JasperReports own markup language (jrxml). You can define datasources to access databases, report variables, fields and parameters. All of these can then be used to populate and display data in your report. Once the report is done you must compile it. Compiled reports can then be processed by JasperReport&#39;s engine to be output in different formats (html, rtf, pdf, xls, printer...)&lt;/p&gt;
&lt;p&gt;Reports can be developed either by hand, editing the report&#39;s source in an editor (jrxml) or with an ide (GUI). There are several GUI editors for JasperReports there even is a NetBeans &lt;a href=&quot;https://jarvis.dev.java.net/&quot;&gt;plugin&lt;/a&gt; (still beta). The one I use and in my opinion the best is &lt;a href=&quot;http://www.jasperforge.org/sf/projects/ireport&quot;&gt;iReport.&lt;/a&gt; &lt;a href=&quot;http://sourceforge.net/project/showfiles.php?group_id=64348&amp;package_id=64215&quot;&gt;Downloading&lt;/a&gt; iReport will be the easiest way to get started with jasper. There is some &lt;a href=&quot;http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/HomePage&quot;&gt;documentation&lt;/a&gt; available on the project&#39;s page too. There you will find very good tutorials and &lt;a href=&quot;http://www.parsera.com/technical_documents/A Tutorial on Reporting in JAVA using JasperReports, iReport abd JFreeChart.pdf&quot;&gt;quick start&lt;/a&gt; articles. The iReport package includes every library/jar you need, so its not necessary to download JasperReports package.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img style=&quot;margin: 5px;text-align:center;&quot; alt=&quot;iReport Main Frame&quot; title=&quot;iReport GUI&quot; src=&quot;http://blog.marcnuri.com/resources/default/0_iReport.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now that you have iReport installed its time to practice report development (learn about bands, groups, fields, variables, parameters, datasources... In further articles I will show you some of the advanced capabilities of these components). If you just want to build reports for data stored in a database (JDBC accessible) you won&#39;t need anything else, just iReport, so don&#39;T worry about integrating jasperreports with your application yet. By now you can get used to run your reports by using the menu option “Build -&amp;gt; Run Report”&lt;/p&gt;
</description>
	    <dc:date>2007-06-19T08:45:34+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/06/19/Getting-started-with-JasperReports-Reporting-in-Java-Part-I?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/06/07/Replacing-Apostrophes-from-Strings-Cleaning-String-to-pass-them-as-SQL-statements">
	    <title>Replacing Apostrophes from Strings // Cleaning String to pass them as SQL statements</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/06/07/Replacing-Apostrophes-from-Strings-Cleaning-String-to-pass-them-as-SQL-statements</link>
        <description>&lt;p&gt;Such a simple thing as replacing an apostrophe with an escape character from a string sometimes can become a very tedious process, more if you&#39;re using String&#39;s &lt;strong&gt;replaceAll(&lt;/strong&gt;...&lt;strong&gt;)&lt;/strong&gt; function. Replacing apostrophes from Strings may be very useful when creating Statements to pass to an SQL database, preventing SQL injection. Many may say that using PreparedStatements is easier and safer, but in many occasions you can&#39;t use prepared statements to accomplish what you need.&lt;/p&gt;
&lt;p&gt;The problem with the replaceAll function comes because of the arguments the function expects. In first place you must pass a regular expression that suits what you want to replace. Secondly, the function expects another regular expression with the String&#39;s replacement. In postgreSQL when passing apostrophes and other special characters as text, you must use the backslash as an escape character, just like in java. So if you want to insert &amp;quot;John&#39;s hand&amp;quot; as an argument to an Insert statement you must write something such as &#39;John\&#39;s hand&#39;.&lt;/p&gt;
&lt;p&gt;If you refer to &lt;a href=&quot;http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html&quot;&gt;Pattern&lt;/a&gt; javadoc you can read:&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;The backslash character (&#39;\&#39;) serves to introduce escaped constructs, as defined in the table above, as well as to quote characters that otherwise would be interpreted as unescaped constructs. Thus the expression \\ matches a single backslash and \{ matches a left brace.&lt;/em&gt;&lt;/blockquote&gt;
&lt;p&gt;Here is the answer to the problem. When replacing &#39; for \&#39; you need to place 4 backslashes before the apostrophe.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
String replacedString = &quot;John&#39;s hand&quot;;
replacedString.replaceAll(&quot;&#39;&quot;,&quot;\\\\&#39;&quot;);
&lt;/pre&gt;
</description>
	    <dc:date>2007-06-07T08:25:07+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/06/07/Replacing-Apostrophes-from-Strings-Cleaning-String-to-pass-them-as-SQL-statements</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/06/07/Replacing-Apostrophes-from-Strings-Cleaning-String-to-pass-them-as-SQL-statements?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/06/06/Detecting-Tab-Key-Pressed-Event-in-JTextField-s-Event-VK-TAB-KeyPressed">
	    <title>Detecting Tab Key Pressed Event in JTextField &#39;s // Event.VK_TAB KeyPressed</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/06/06/Detecting-Tab-Key-Pressed-Event-in-JTextField-s-Event-VK-TAB-KeyPressed</link>
        <description>&lt;p&gt;Adding a &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyListener.html&quot;&gt;KeyListener&lt;/a&gt; to a &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTextField.html&quot;&gt;JTextField&lt;/a&gt; to detect KeyPressed events is pretty straight forward. Buy maybe you have encountered some problems when trying to detect special key such as TAB&#39;s. This issue is due to LowLevel &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html&quot;&gt;keyEvents&lt;/a&gt; captured by Swing&#39;s default FocusTraversalKeys. What we need to do to capture the VK_TAB &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html&quot;&gt;KeyEvent&lt;/a&gt; is to remove the default FocusTraversalKeys from the component.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
        myJTextField.setFocusTraversalKeys(
                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
&lt;/pre&gt;
&lt;p&gt;Once we&#39;ve done this with the component, the tab KeyEvent will not be captured by swing&#39;s default focus traversal keys and we will be able to add events normally.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
myJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
    &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;void&lt;/span&gt; keyPressed(java.awt.event.&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;KeyEvent&lt;/span&gt; evt) {
        &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;if&lt;/span&gt;(evt.getKeyCode() == evt.VK_TAB){
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* PUT YOUR STUFF HERE OR CALL A FUNCTION */&lt;/span&gt;
            doSomething();
            &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* If you want to change the focus to the next component */&lt;/span&gt;
            nextJComponent.grabFocus();
    }
}&lt;span style=&quot;&quot;&gt;)&lt;/span&gt;;
&lt;/pre&gt;
</description>
	    <dc:date>2007-06-06T12:50:00+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/06/06/Detecting-Tab-Key-Pressed-Event-in-JTextField-s-Event-VK-TAB-KeyPressed</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/06/06/Detecting-Tab-Key-Pressed-Event-in-JTextField-s-Event-VK-TAB-KeyPressed?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/05/30/Dynamic-icons-for-your-JComponents-Create-an-icon-JButton-with-dynamic-icons">
	    <title>Dynamic icons for your JComponents // Create an icon JButton with dynamic icons.</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/05/30/Dynamic-icons-for-your-JComponents-Create-an-icon-JButton-with-dynamic-icons</link>
        <description>&lt;p&gt;Internet offers many opportunities and possibilities for developers with imagination. Today, most search engines and specialized sites count with API&#39;s to access their data from other software, sites, devices...&lt;/p&gt;
&lt;p&gt;Today I&#39;m going to show you a dirty example of how this apis can benefit your program. In less of ten lines of code (someone intelligent would have done it in less) I will add an Icon to a jButton with an image stored in the net.&lt;/p&gt;
&lt;p&gt;To do this I will use yahoo&#39;s Image Search API, documentation can be found &lt;a href=&quot;http://developer.yahoo.com/search/image/V1/imageSearch.html&quot;&gt;here&lt;/a&gt;. For demonstration purposes I will use the YahooDemo applicationId, you will need to create one if you intend to use this api in your programs.&lt;/p&gt;
&lt;p&gt;In brief, what the program does is decode what the browser gets when it reads an url constructed with the api guidelines. The response is an XML inputStream where you can get the url of a thumbnailed image which you can then pass to the JButton.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
try {
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;URL&lt;/span&gt; pepe = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;URL&lt;/span&gt;(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&amp;amp;query=client%20icon&amp;amp;results=1&amp;amp;format=gif&quot;&lt;/span&gt;);
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;BufferedReader&lt;/span&gt; br = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;BufferedReader&lt;/span&gt;(&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;InputStreamReader&lt;/span&gt;(pepe.openStream()));
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;String&lt;/span&gt; text =&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&quot;&lt;/span&gt;;
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;String&lt;/span&gt; line = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;;
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;while&lt;/span&gt;((line = br.readLine()) != &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;null&lt;/span&gt;){
                text += line+&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&lt;/span&gt;;
            }
            text = text.substring(text.indexOf(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&amp;lt;Thumbnail&amp;gt;&quot;&lt;/span&gt;));
            text = text.substring(text.indexOf(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&amp;lt;Url&amp;gt;&quot;&lt;/span&gt;)+5, text.indexOf(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;&amp;lt;/Url&amp;gt;&quot;&lt;/span&gt;));
            BufferedImage img = ImageIO.read(&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;URL&lt;/span&gt;(text));
            jButton1.setIcon(
                    &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; ImageIcon(img));
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
&lt;/pre&gt;
&lt;p&gt;When you run this code this is what you get:&lt;br /&gt;&lt;img style=&quot;margin: 5px&quot; alt=&quot;Customer&quot; src=&quot;http://blog.marcnuri.com/resources/default/0_customer.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;As you can see the program is quite simple. In the first part, you generate an URL with the desired variables.
In this case, we want a customer icon in a gif format. You can refer to the api guide to customize your URL.
In second place, we get the contents of the URL and parse it to get the location of the thumbnail image.
Finally we get the thumbnailed image using ImageIO.&lt;/p&gt;
&lt;p&gt;You can download a running version of the code &lt;a href=&quot;http://blog.marcnuri.com/resources/default/0_imageButton.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
	    <dc:date>2007-05-30T09:16:08+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/05/30/Dynamic-icons-for-your-JComponents-Create-an-icon-JButton-with-dynamic-icons</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/05/30/Dynamic-icons-for-your-JComponents-Create-an-icon-JButton-with-dynamic-icons?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/05/23/JTable-detecting-selection-changes-ListSelectionListener-Selection-Changed-Event">
	    <title>JTable, detecting selection changes //   ListSelectionListener /*Selection Changed Event*/</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/05/23/JTable-detecting-selection-changes-ListSelectionListener-Selection-Changed-Event</link>
        <description>&lt;p&gt;When working with tables, it may be useful to detect selection changes. If for example, you need to sum the values of a specified column in a selection range, this method will be most essential.&lt;/p&gt;
&lt;p&gt;If you explore the available methods to add listeners to a JTable, you will notice there&#39;s no such thing as a selectionListener. This is because the JTable has its own selection model, where you can add the listener.&lt;/p&gt;
&lt;p&gt;The following code illustrates the way to go to add a selection listener:&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;JTable jtable = new JTable();
jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;public&lt;/span&gt; &lt;span style=&#39;color:#7f0055; font-weight:bold; &#39;&gt;void&lt;/span&gt; valueChanged(ListSelectionEvent e) {
        &lt;span style=&#39;color:#3f7f59; &#39;&gt;/*&lt;/span&gt;&lt;span style=&#39;color:#ffffff; background:#808000; &#39;&gt;TODO: Add whatever you need to do when the selection changes &lt;/span&gt;&lt;span style=&#39;color:#3f7f59; &#39;&gt;*/&lt;/span&gt;
    }
});
&lt;/pre&gt;
</description>
	    <dc:date>2007-05-23T17:25:57+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/05/23/JTable-detecting-selection-changes-ListSelectionListener-Selection-Changed-Event</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/05/23/JTable-detecting-selection-changes-ListSelectionListener-Selection-Changed-Event?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/05/21/SimpleDateFormat-to-check-user-date-input-parsing-String-to-dates-in-java">
	    <title>SimpleDateFormat to check user date input // parsing String to dates in java</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/05/21/SimpleDateFormat-to-check-user-date-input-parsing-String-to-dates-in-java</link>
        <description>&lt;p&gt;When developing user interfaces for management software you usually need to check what the user inputs in order to store the values in a database or a file. Java offers different alternative to parse String (normally the way user inputs values to the system) to other data types.&lt;/p&gt;
&lt;p&gt;The class &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html&quot;&gt;SimpleDateFormat&lt;/a&gt; from the package java.text offers a simple method to do this. You just have to  call parse(String youDate) in order to get a &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html&quot;&gt;java.util.Date&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Following you can find some code which explains this method and some of its particularities:&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
&lt;span style=&quot;color:#3f7f59; &quot;&gt;/* We create the SimpleDateFormat object with the desired patter */&lt;/span&gt;
        SimpleDateFormat sdf = new SimpleDateFormat(&quot;dd/MM/yyyy&quot;);
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* This is very important. If you need strict parsing, (i.e. January&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * will only have 31 days you must set this to false.&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * If you don&#39;t do this when you parse &quot;32/01/2007&quot; the date you&#39;ll&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * you&#39;ll get really be 01/02/2007*/&lt;/span&gt;
        sdf.setLenient(false);
        try {
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;System&lt;/span&gt;.out.println(sdf.parse(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;25/12/2022&quot;&lt;/span&gt;));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* This first parse offers no problem, when run you will get&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * Sun Dec 25 00:00:00 CET 2022&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * in the console*/&lt;/span&gt;

        try {
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;System&lt;/span&gt;.out.println(sdf.parse(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;34/15/2002&quot;&lt;/span&gt;));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* In this case, the date is wrong thus we will get the correspondant&lt;/span&gt; 
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        *  exception */&lt;/span&gt;
        try {
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;System&lt;/span&gt;.out.println(sdf.parse(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;28/02/202&quot;&lt;/span&gt;));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* This time we will not get an exception, but in some cases we would like&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        to get the exception, because this date although valid, has an uncommon&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        length and may be due to an input error.*/&lt;/span&gt;

    &lt;span style=&quot;color:#3f7f59; &quot;&gt;/*To solve the above proble, we could create the following function:*/&lt;/span&gt;
    &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;public&lt;/span&gt; Date parseDate(String date) &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;throws&lt;/span&gt; ParseException{
        &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;SimpleDateFormat&lt;/span&gt; sdf = &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;SimpleDateFormat&lt;/span&gt;(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;dd/MM/yyyy&quot;&lt;/span&gt;);
        sdf.setLenient(&lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;false&lt;/span&gt;);
        &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;if&lt;/span&gt;(date.length() != 10){
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;ParseException&lt;/span&gt;(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;Date with wrong length: &quot;&lt;/span&gt;+date, 0);
        }
        &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;return&lt;/span&gt; sdf.parse(date);
    }
&lt;/pre&gt;
</description>
	    <dc:date>2007-05-21T11:09:58+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/05/21/SimpleDateFormat-to-check-user-date-input-parsing-String-to-dates-in-java</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/05/21/SimpleDateFormat-to-check-user-date-input-parsing-String-to-dates-in-java?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/05/07/Numbers-to-Strings-with-custom-symbols-DecimalFormat-DecimalFormatSymbols">
	    <title>Numbers to Strings with custom symbols // DecimalFormat - DecimalFormatSymbols</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/05/07/Numbers-to-Strings-with-custom-symbols-DecimalFormat-DecimalFormatSymbols</link>
        <description>&lt;p&gt;When printing reports or casting Strings to Numbers, its very useful to use the &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html&quot;&gt;DecimalFormat&lt;/a&gt; class found in java.text. This class is pretty straightforward and easy to use, but some problems may be found when your work with this class in computers from other countries. Internationalization will cause your program to behave in a way you may not expect in some cases.&lt;/p&gt;
&lt;p&gt;If you use these class to parse a number to a String, you may find that when a user enters a number in a french computer you will be getting a ParseException, because the computer is expecting different symbols. Here is where the &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormatSymbols.html&quot;&gt;DecimalFormatSymbols&lt;/a&gt; class becomes very useful.&lt;/p&gt;
&lt;p&gt;With the following code I&#39;ll show you how easy is to change the symbols and make them independent of different Locales.&lt;br /&gt;&lt;/p&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
&lt;span style=&quot;color:#3f7f59; &quot;&gt;/* We create our formatter using a DecimalFormat Instance.&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * We use these method instead of (new DecimalFormat(String pattern))&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * because in computers with different locales, we may have problems when&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * setting the pattern. This way we assure we always work with the same variables.&lt;/span&gt;
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        **/&lt;/span&gt;
        DecimalFormat format = (DecimalFormat)DecimalFormat.getInstance(Locale.ENGLISH);
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* We set the typical pattern with thousand separator and two decimal places */&lt;/span&gt;
        format.applyPattern(&quot;#,##0.00&quot;);
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* Now we do the work to change the formatting symbols&lt;/span&gt; 
 &lt;span style=&quot;color:#3f7f59; &quot;&gt;        * We will set the typical spanish symbols*/&lt;/span&gt;
        DecimalFormatSymbols dfs = format.getDecimalFormatSymbols();
        dfs.setDecimalSeparator(&#39;,&#39;);
        dfs.setGroupingSeparator(&#39;.&#39;);
        format.setDecimalFormatSymbols(dfs);
        &lt;span style=&quot;color:#3f7f59; &quot;&gt;/* We do two simple tests */&lt;/span&gt;
        System.out.println(format.format(1000234234.56772345d));
        try {
            &lt;span style=&quot;color:#7f0055; font-weight:bold; &quot;&gt;System&lt;/span&gt;.out.println(format.parse(&lt;span style=&quot;color:#2a00ff; &quot;&gt;&quot;1.258.254,25&quot;&lt;/span&gt;));
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
&lt;/pre&gt;
</description>
	    <dc:date>2007-05-07T06:49:17+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/05/07/Numbers-to-Strings-with-custom-symbols-DecimalFormat-DecimalFormatSymbols</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/05/07/Numbers-to-Strings-with-custom-symbols-DecimalFormat-DecimalFormatSymbols?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://blog.marcnuri.com/blog/default/2007/04/18/Java-recursive-functions-explained-Using-recursion-to-sum-an-array-of-numbers">
	    <title>Java recursive functions explained // Using recursion to sum an array of numbers</title>
	    <link>http://blog.marcnuri.com/blog/default/2007/04/18/Java-recursive-functions-explained-Using-recursion-to-sum-an-array-of-numbers</link>
        <description>&lt;p&gt;Java is a very powerful object oriented language. If you search for recursion in &lt;a href=&quot;http://en.wikipedia.org/wiki/Recursion&quot;&gt;wikipedia&lt;/a&gt; you will find this definition &lt;em&gt;&amp;quot;&lt;strong&gt;Recursion&lt;/strong&gt;, in &lt;a href=&quot;http://en.wikipedia.org/wiki/Mathematics&quot; title=&quot;Mathematics&quot;&gt;mathematics&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Computer_science&quot; title=&quot;Computer science&quot;&gt;computer science&lt;/a&gt;, is a method of defining &lt;a href=&quot;http://en.wikipedia.org/wiki/Function&quot; title=&quot;Function&quot;&gt;functions&lt;/a&gt; in which the function being defined is applied within its own definition.&amp;quot;&lt;/em&gt; This means, that the function will call itself again and again until it gets the correct answer.&lt;/p&gt;
&lt;p&gt;There are many pages where you can find great explanations to recursion theory. Most of them use the example of the Towers of Hanoi:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.cut-the-knot.org/recurrence/hanoi.shtml&quot;&gt;Cut The Knot --Towers of Hanoi--&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.cs.cmu.edu/~cburch/pgss97/slides/0716-recurse.html&quot;&gt;Recursion --Towers of Hanoi--&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://danzig.jct.ac.il/java_class/recursion.html&quot;&gt;Java Recursion with examples&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What I&#39;m going to show you is an easy way to sum arrays of numbers. This example lets you see how easy can recursion be and how useful it is.&lt;/p&gt;
&lt;pre id=&quot;code&quot; style=&quot;white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: o-pre-wrap;&quot;&gt;
&lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;class&lt;/span&gt; recursive &lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
    &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;public&lt;/span&gt; recursive&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#3f5fbf; &quot;&gt;/** We create the array of numbers we want to sum&lt;/span&gt;
 &lt;span style=&quot;color:#3f5fbf; &quot;&gt;                   It can be any subclass of java&lt;/span&gt;&lt;span style=&quot;color:#008c00; &quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3f5fbf; &quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color:#008c00; &quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#3f5fbf; &quot;&gt;Number*/&lt;/span&gt;
                &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Double&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt; test &lt;span style=&quot;color:#808030; &quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;100d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color:#008000; &quot;&gt;0.&lt;/span&gt;05d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 88d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 99d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color:#008000; &quot;&gt;0.&lt;/span&gt;05d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 88d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 99d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color:#008000; &quot;&gt;0.&lt;/span&gt;05d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 88d&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; 99d&lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
                &lt;span style=&quot;color:#696969; &quot;&gt;/* We call our function */&lt;/span&gt;
                &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;System&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;out&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;println&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;test&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
    &lt;span style=&quot;color:#696969; &quot;&gt;/* This is the initial function, it calculates the starting fields and results&lt;/span&gt;
 &lt;span style=&quot;color:#696969; &quot;&gt;    *automatically*/&lt;/span&gt;
    &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Number&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt; numbers&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
        &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;length &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; numbers&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;length &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
    &lt;span style=&quot;color:#696969; &quot;&gt;/* This is our RECURSIVE FUNCTION */&lt;/span&gt;
    &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Number&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Number&lt;/span&gt; initialValue&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt; numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color:#bb7977; &quot;&gt;int&lt;/span&gt; location&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt; 
        &lt;span style=&quot;color:#696969; &quot;&gt;/* If we&#39;ve reached the end of the array we return the final RESULT */&lt;/span&gt;
        &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; initialValue&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
        &lt;span style=&quot;color:#696969; &quot;&gt;/* Or else we are recursive */&lt;/span&gt;
        &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
            &lt;span style=&quot;color:#696969; &quot;&gt;/*First we cast the java.lang.Number to its subclass so we can do the&lt;/span&gt; 
 &lt;span style=&quot;color:#696969; &quot;&gt;            *sum */&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt; &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigInteger&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigInteger&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;add&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigInteger&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigDecimal&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigDecimal&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;.&lt;/span&gt;add&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;BigDecimal&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Byte&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Byte&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Byte&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Double&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Double&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Double&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Integer&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Integer&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Integer&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Long&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Long&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Long&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;numbers &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;instanceof&lt;/span&gt;  &lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Short&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Short&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Short&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
            &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
                &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;return&lt;/span&gt; sum&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Float&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;initialValue&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;Float&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;numbers&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;location&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        numbers&lt;span style=&quot;color:#808030; &quot;&gt;,&lt;/span&gt;
                        &lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;location &lt;span style=&quot;color:#808030; &quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color:#008c00; &quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;
            &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
        &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;   
    &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
    &lt;span style=&quot;color:#696969; &quot;&gt;/* THis is our main method */&lt;/span&gt;
    &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color:#bb7977; &quot;&gt;void&lt;/span&gt; main&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#bb7977; font-weight:bold; &quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;]&lt;/span&gt; args&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:#800080; &quot;&gt;{&lt;/span&gt;
        &lt;span style=&quot;color:#800000; font-weight:bold; &quot;&gt;new&lt;/span&gt; recursive&lt;span style=&quot;color:#808030; &quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#808030; &quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#800080; &quot;&gt;;&lt;/span&gt;      
    &lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color:#800080; &quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
</description>
	    <dc:date>2007-04-18T10:10:22+02:00</dc:date>
	                                <wfw:comment>http://blog.marcnuri.com/commentapi/default/Java/2007/04/18/Java-recursive-functions-explained-Using-recursion-to-sum-an-array-of-numbers</wfw:comment>
            <wfw:commentRss>http://blog.marcnuri.com/blog/default/2007/04/18/Java-recursive-functions-explained-Using-recursion-to-sum-an-array-of-numbers?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
    
</rdf:RDF>
