<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Roger Cuddy &#187; Programming</title>
	<atom:link href="http://www.rogercuddy.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rogercuddy.com</link>
	<description>This site just holds copies of whatever I&#039;ve posted around the net. YMMV</description>
	<lastBuildDate>Wed, 20 Jul 2011 03:59:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Perl state variables</title>
		<link>http://www.rogercuddy.com/programming/perl-state-variables/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/perl-state-variables/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 04:59:06 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Perl state variables]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=259</guid>
		<description><![CDATA[<p>Perl 5.10 added a new class of variables &#8216;state&#8217; that are similar to &#8216;my&#8217; in scope but are only initialized once. Even inside of a subroutine a state variable will only be initialized on the first call to the subroutine and will maintain it&#8217;s last value between calls. A simple example is the easiest [...]]]></description>
			<content:encoded><![CDATA[<p>Perl 5.10 added a new class of variables &#8216;state&#8217; that are similar to &#8216;my&#8217; in scope but are only initialized once. Even inside of a subroutine a state variable will only be initialized on the first call to the subroutine and will maintain it&#8217;s last value between calls. A simple example is the easiest way to show how state works. In the code below the two subroutines are identical except that the variable $countval is declared with my in the first sub (non_state_count) and with state in the second sub (state_count). This means the $countval variable will be initialized on every call to non_state_count and will not maintain it&#8217;s value between calls. In state_count it&#8217;s the opposite and $countval will initialize only once and then maintain it&#8217;s last value between calls.</p>
<pre class="brush: perl; ">

#! /usr/bin/perl
use feature qw(state);

print &quot;Result of calls to non_state_count\n&quot;;
for ($i = 0; $i &lt; 10; $i++) {
    print non_state_count() . &#039; &#039;;
}
print &quot;\n notice that the variable countval is reinitialized on every call\n&quot;;

print &quot;Result of calls to state_count\n&quot;;
for ($i = 0; $i &lt; 10; $i++) {
    print state_count() . &#039; &#039;;
}
print &quot;\n observe that the variable countval now retains its value between calls\n&quot;;

sub non_state_count {
    my $countval;
  return ++$countval;
}

sub state_count {
    state $countval;
  return ++$countval;
}
</pre>
<p>You should see the output of the script as: </p>
<table border=1>
<tr>
<td>
Result of calls to non_state_count<br />
<mark>1 1 1 1 1 1 1 1 1 1 </mark><br />
 notice that the variable countval is reinitialized on every call
</td>
<td>
Result of calls to state_count<br />
<mark>1 2 3 4 5 6 7 8 9 10 </mark><br />
 observe that the variable countval now retains its value between calls
</td>
</tr>
</table>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/perl-state-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDK 7 &#8211; Try with Resources</title>
		<link>http://www.rogercuddy.com/programming/jdk-7-try-with-resources/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/jdk-7-try-with-resources/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 23:38:23 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JDK 7]]></category>
		<category><![CDATA[Roger Cuddy]]></category>
		<category><![CDATA[try-with-resources]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=251</guid>
		<description><![CDATA[<p>JDK 7 has several enhancements to the try-catch construct. Try with resources allows for ensuring that resources are closed and freed up without the need to explicitly call the close function. Any class implementing java.lang.AutoCloseable can be automatically closed without the need for a finally section in the try block.</p> <p>The syntax is a [...]]]></description>
			<content:encoded><![CDATA[<p>JDK 7 has several enhancements to the try-catch construct. Try with resources allows for ensuring that resources are closed and freed up without the need to explicitly call the close function. Any class implementing java.lang.AutoCloseable can be automatically closed without the need for a finally section in the try block.</p>
<p>The syntax is a try with parens and the resources to automatically close out inside the parens.<br />
<b>try ( resources ) { code } catch (exception) { } </b></p>
<p>snippet 1 shows the syntax for try with resources:</p>
<pre class="brush: java; ">

try (
    BufferedReader reader = new BufferedReader(
        new FileReader(&quot;c:/dev/jdk7test/t1.ofx&quot;));
   BufferedWriter writer = new BufferedWriter(
        new FileWriter(&quot;c:/dev/jdk7test/output.txt&quot;))
   ) {
         // read and write
     }
</pre>
<p>Another change to try is that the catch can now handle multiple exception types in one block. Multiple catch blocks are optional and still work fine if you prefer to separate the handling. Just separate the exception types with | .</p>
<p>Snippet 2 catch with multiple exception types:</p>
<pre class="brush: java; ">

catch (java.io.FileNotFoundException | java.io.IOException ex) {
    System.out.println(ex.getMessage());
}
</pre>
<p>Lastly here is a small simple class that shows both features in action. </p>
<pre class="brush: java; ">

package jdk7test;
import java.io.*;
public class Jdk7TryWithResourcesTest {
    public static void main(String[] args) {
        Jdk7TryWithResourcesTest test = new Jdk7TryWithResourcesTest();
        test.execute();
    }

    public void execute() {
        try (
                BufferedReader reader = new BufferedReader(new FileReader(&quot;c:/dev/jdk7test/t1.ofx&quot;));
                BufferedWriter writer = new BufferedWriter(new FileWriter(&quot;c:/dev/jdk7test/output.txt&quot;))
            ) {
            String line;
            while ((line = reader.readLine()) != null){
                writer.write(line);
            }
        } catch (java.io.FileNotFoundException | java.io.IOException ex) {
            System.out.println(ex.getMessage());
        }
    }
}
</pre>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/jdk-7-try-with-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDK 7 &#8211; use Strings in switch statements</title>
		<link>http://www.rogercuddy.com/programming/jdk-7-use-strings-in-switch-statements-2/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/jdk-7-use-strings-in-switch-statements-2/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 20:29:30 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JDK 7]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=247</guid>
		<description><![CDATA[<p>JDK 7 adds the ability to use String objects as the case in switch blocks. It&#8217;s not exactly an earth shattering addition but I find it quite useful in avoiding long if-then chains. Plus the release docs claim that using a switch is more efficient.</p> <p>At the bottom of this post is a small [...]]]></description>
			<content:encoded><![CDATA[<p>JDK 7 adds the ability to use String objects as the case in switch blocks. It&#8217;s not exactly an earth shattering addition but I find it quite useful in avoiding long if-then chains. Plus the release docs claim that using a switch is more efficient.</p>
<p>At the bottom of this post is a small java class that provides a complete example of use. Here is the part we&#8217;re concerned about. The switch takes a String argument that should be the abbreviated name of a month and sets the return value to the quarter of the year that month is in.</p>
<pre class="brush: java; ">

switch(monthIn) {
            case &quot;Jan&quot;:
            case &quot;Feb&quot;:
            case &quot;Mar&quot;:
                retval = &quot;Q1&quot;;
                break;
            case &quot;Apr&quot;:
            case &quot;May&quot;:
            case &quot;Jun&quot;:
                retval = &quot;Q2&quot;;
                break;
            case &quot;Jul&quot;:
            case &quot;Aug&quot;:
            case &quot;Sep&quot;:
                retval = &quot;Q3&quot;;
                break;
            case &quot;Oct&quot;:
            case &quot;Nov&quot;:
            case &quot;Dec&quot;:
                retval = &quot;Q4&quot;;
                break;
            default:
                throw new IllegalArgumentException(&quot;Invalid Month argument: &quot; + monthIn);
}
</pre>
<p>That&#8217;s a pretty geedunk example but it shows the functionality and is simple to read/understand. Here is a complete class that shows the same switch statement in use:</p>
<pre class="brush: java; ">

package jdk7test;
import java.util.Calendar;

public class Jdk7test {
    public static void main(String args[]) {
        Jdk7test test = new Jdk7test();
        test.execute();
    }

    public void execute() {
        String[] strMonths = new String[] { &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;,
                                            &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot; };
        Calendar cal = Calendar.getInstance();
        try {
            String monthName = strMonths[cal.get(Calendar.MONTH)];
            String quarter = getQuarter(monthName);
            System.out.println(&quot;Month: &quot; +  monthName + &quot; is in quarter: &quot;
                               + quarter);
        } catch (IllegalArgumentException e) {
            System.out.println(&quot;The month sent to getQuarter was invalid&quot;);
            System.out.println(e.getMessage());
        }
    }

    public String getQuarter(String monthIn) {
        String retval;
        switch(monthIn) {
            case &quot;Jan&quot;:
            case &quot;Feb&quot;:
            case &quot;Mar&quot;:
                retval = &quot;Q1&quot;;
                break;
            case &quot;Apr&quot;:
            case &quot;May&quot;:
            case &quot;Jun&quot;:
                retval = &quot;Q2&quot;;
                break;
            case &quot;Jul&quot;:
            case &quot;Aug&quot;:
            case &quot;Sep&quot;:
                retval = &quot;Q3&quot;;
                break;
            case &quot;Oct&quot;:
            case &quot;Nov&quot;:
            case &quot;Dec&quot;:
                retval = &quot;Q4&quot;;
                break;
            default:
                throw new IllegalArgumentException(&quot;Invalid Month argument: &quot; + monthIn);
        }
        return retval;
    }
}
</pre>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/jdk-7-use-strings-in-switch-statements-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDK 7 release candidate now available</title>
		<link>http://www.rogercuddy.com/programming/jdk-7-first-release-candidate/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/jdk-7-first-release-candidate/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 16:17:28 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=231</guid>
		<description><![CDATA[<p>Build 147 for JDK 7 is now available with the goal of a generally available release later this month. Some good resources are: Oracle&#8217;s Java 7 wiki Java 7 project page Get the release from the download page Oracle&#8217;s Java SE 7 documentation <p>As I test out the release I&#8217;ll do some posts on [...]]]></description>
			<content:encoded><![CDATA[<p>Build 147 for JDK 7 is now available with the goal of a generally available release later this month. Some good resources are: 
<ul>
<li><a target="_blank" href="http://wikis.sun.com/display/JDK7/Home">Oracle&#8217;s Java 7 wiki</a></li>
<li><a target="_blank" href="http://openjdk.java.net/projects/jdk7/">Java 7 project page</a></li>
<li>Get the release from the <a target="_blank" href="http://jdk7.java.net/download.html">download page</a></li>
<li>Oracle&#8217;s <a target="_blank" href="http://download.oracle.com/javase/7/docs/index.html">Java SE 7 documentation</a></li>
</ul>
<p>As I test out the release I&#8217;ll do some posts on new features. </p>
<p>&nbsp;</p>
<p class="technorati-tags"><a href="http://technorati.com/tag/Java" rel="tag">Java</a>, <a href="http://technorati.com/tag/Java%207" rel="tag">Java 7</a>, <a href="http://technorati.com/tag/JDK%207" rel="tag">JDK 7</a>, <a href="http://technorati.com/tag/Roger%20Cuddy" rel="tag">Roger Cuddy</a></p>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/jdk-7-first-release-candidate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl 5.12 using each with arrays</title>
		<link>http://www.rogercuddy.com/programming/perl-5-12-using-each-with-arrays/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/perl-5-12-using-each-with-arrays/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 19:48:12 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=218</guid>
		<description><![CDATA[<p>As of version 5.12 perl now supports using each with arrays and hashes both. For our pm project we should get in habit of using it. No need to rewrite any old code.</p> <p>In practice it’s very much the same as use with hashes. each still returns 2 results with the first one being [...]]]></description>
			<content:encoded><![CDATA[<p>As of version 5.12 perl now supports using each with arrays and hashes both. For our pm project we should get in habit of using it. No need to rewrite any old code.</p>
<p>In practice it’s very much the same as use with hashes. each still returns 2 results with the first one being the index in the array instead of the key for a hash. This lets us use the convenience of a while loop to step through the array getting both the index and value.</p>
<p>Short simple example:</p>
<pre class="brush: perl; ">

my @arr = qw(test1 test2 test3 test4);
while (my ($idx, $val) = each @arr) {
	print($idx, $val);
};
</pre>
<p>gives output:</p>
<pre>0, test1
1, test2
2, test3
3, test4</pre>
<p>The iterator here will respond to changes in the array inside the while block. I really don’t recommend changing inside the loop but just as an example:</p>
<pre class="brush: perl; ">

my @arr = qw(test1 test2 test3 test4);
while (my ($idx, $val) = each @arr) {
  if ($idx == 3) {
    push @arr,&quot;test5&quot;;
  }
  print(&quot;$idx, $val\n&quot;);
};
</pre>
<p>will output:</p>
<pre>0, test1
1, test2
2, test3
3, test4
4, test5</pre>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/perl-5-12-using-each-with-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Perl under your home directory</title>
		<link>http://www.rogercuddy.com/programming/installing-perl-under-your-home-directory/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/installing-perl-under-your-home-directory/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 02:53:06 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/?p=191</guid>
		<description><![CDATA[<p>The question of how to do a local install of PERL comes up now and then. The truth is it&#8217;s quite simple if you have a normal set of build tools installed. GCC, make, etc. I will walk through the steps here on doing the build and install. </p> Decide where you wish to [...]]]></description>
			<content:encoded><![CDATA[<p>The question of how to do a local install of PERL comes up now and then. The truth is it&#8217;s quite simple if you have a normal set of build tools installed. GCC, make, etc. I will walk through the steps here on doing the build and install. </p>
<ol>
<li>Decide where you wish to put the install. For example my work box has Perl 5.10 installed for the operating system but I use 5.12 to develop. To do this I have version 5.12.2 installed into the directory tree at ~/tools/perl .</li>
<li>Download the version source you wish to install from <a href="http://www.perl.org/get.html" title="http://www.perl.org/get.html" target="_blank">http://www.perl.org/get.html</a> . At the time I write this 5.12.2 is the latest stable version. </li>
<li>Uncompress &amp; untar the source into a work directory and cd into the work directory</li>
<li>Now the important part. We must pass to Configure the value of the directory we want to install to. This is passed as the <em>prefix</em> . For example ./Configure -des -Dprefix=/home/rcuddy/tools/perl </li>
<li>Perform the make steps.</li>
<li>Make</li>
<li>Make test</li>
<li>Make install</li>
</ol>
<p>This will build Perl and install it into the directory you set with the prefix option for Configure. If you want to make this your default Perl then edit your path setup to put the perl/bin directory in front of the system paths. Example: PATH=~/tools/perl/bin:$PATH</p>
<p>Installing extra modules to your new tree is also very easy. Just make sure the cpan or cpanp you run is from the bin directory of the new tree. If you setup the new install as your default Perl then just run them as normal and the operations will be performed on the local install. </p>
<p>I told you it was easy <img src='http://www.rogercuddy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. Yes it is possible to have any number of different versions installed this way as long as you use different prefix settings and of course are careful about calling the right binary. </p></p>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/installing-perl-under-your-home-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poor Man Facebook Library Project note 1 &#8211; Setting up your environment to build</title>
		<link>http://www.rogercuddy.com/programming/poor-man-facebook-library-project-note-1-setting-up-your-environment-to-build/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/poor-man-facebook-library-project-note-1-setting-up-your-environment-to-build/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 10:23:42 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Facebook Java]]></category>
		<category><![CDATA[Poor Man Face Book Library]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/programming/poor-man-facebook-library-project-note-1-setting-up-your-environment-to-build/</guid>
		<description><![CDATA[<p>We’re still a bit undecided on whether to use the library website to post items intended only to the dev team. For now dev items will be posted on my SourceForge site and at Poor’s site both. </p> <p>Poor and I have tried to structure the build process to minimize special requirements on any [...]]]></description>
			<content:encoded><![CDATA[<p>We’re still a bit undecided on whether to use the library website to post items intended only to the dev team. For now dev items will be posted on <a href="http://rogercuddy.users.sourceforge.net" target="_blank">my SourceForge site</a> and at <a href="http://www.poor-man.com" target="_blank">Poor’s site</a> both. </p>
<p>Poor and I have tried to structure the build process to minimize special requirements on any developer’s machine . So far at least we’ve been able to keep it pretty mild, especially if you only have the developer role. Most developers will already have everything they need installed. </p>
<hr />
<p>To develop and build</p>
<ul>
<li>Text Editor of your choice. Use whichever tool you normally do but <u>DO NOT</u> check IDE specific files into the source repository. </li>
<li><a href="http://subversion.tigris.org/" target="_blank">Subversion</a> (and a GUI if you wish) </li>
<li><a href="http://java.sun.com/javase/downloads/index.jsp" target="_blank">JDK 1.6 SE</a> </li>
<li><a href="http://ant.apache.org/index.html" target="_blank">Ant 1.7.1</a> </li>
<li>Optional – <a href="http://pmd.sourceforge.net/" target="_blank">PMD</a> installed for use by Ant, <a href="http://pmd.sourceforge.net/ant-task.html" target="_blank">ant task doc</a> </li>
</ul>
<hr />
<p>If you will be working on the website then you need to add a little more</p>
<ul>
<li>Pushing to the website via the build script requires that your ssh key be registered with sourceforge. We very much do not want any user ids and passwords embedded in the script at any time. It’s just too easy&#160; to forget and check in build.xml with your id / pw now publicly available. </li>
<li>Pushing from Ant requires you have optional library <a href="http://www.jcraft.com/jsch/" target="_blank">JSch</a> installed. </li>
</ul>
<p>&#160;</p>
<p>That’s it for now anyway. Changes will be posted as new articles so they are easy to catch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/poor-man-facebook-library-project-note-1-setting-up-your-environment-to-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This should be interesting&#8230;</title>
		<link>http://www.rogercuddy.com/programming/this-should-be-interesting/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/this-should-be-interesting/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 19:19:52 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Roger Cuddy]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/programming/this-should-be-interesting/</guid>
		<description><![CDATA[<p>Can you really run a functioning WordPress blog on Source Forge&#8217;s user space? We&#8217;re going to find out. My first thought about installing was admittedly &#8216;this is going to hurt!&#8217;. Once setup it will be accessible at Rog&#8217;s SF Notes</p> <p>&#60;edit&#62;The install went well. You can read about it at the follow up post [...]]]></description>
			<content:encoded><![CDATA[<p>Can you really run a functioning WordPress blog on Source Forge&#8217;s user space? We&#8217;re going to find out. My first thought about installing was admittedly &#8216;this is going to hurt!&#8217;. Once setup it will be accessible at <a href="http://rogercuddy.users.sourceforge.net" target="_blank">Rog&#8217;s SF Notes</a></p>
<p>&lt;edit&gt;The install went well. You can read about it at the <a href="http://www.rogercuddy.com/sourceforge/installing-and-running-wordpress-on-sourceforge/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" title="follow up post">follow up post</a> &lt;end edit&gt;</p>
<p>Goals: </p>
<ol>
<li>Be able to install themes and plugins. </li>
<li>Responsive enough that it drives readers mad waiting on pages to render. </li>
<li>Support sitemaps </li>
<li>Easy to backup/restore both the database and the file system. </li>
<li>Allow multiple contributors </li>
</ol>
<p> </p>
<p>Quite modest but if I can get that much working I’ll be pretty happy. #1 itself rules out using SF’s Hosted Apps as it won’t be possible to use any themes or plugins. </p>
<p>Will post soon on how it all went. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/this-should-be-interesting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Combining Derby embedded mode and server mode</title>
		<link>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 10:25:21 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Derby]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/combining-derby-embedded-mode-and-server-mode-60.htm</guid>
		<description><![CDATA[<p>Recently there have been several occasions where I have needed an application to use an embedded driver but also needed to allow for the occasional login to the database externally while the application is executing. Derby works wonderfully for this and starting a server within the application is exceedingly simple. Here I will give [...]]]></description>
			<content:encoded><![CDATA[<p>Recently there have been several occasions where I have needed an application to use an embedded driver but also needed to allow for the occasional login to the database externally while the application is executing. Derby works wonderfully for this and starting a server within the application is exceedingly simple. Here I will give just a brief example that should be enough to demonstrate the method. The code fragments here are admittedly simplistic but they work and show the principles cleanly. </p>
<pre><span style=" font-family:'Courier New,courier';"> </span></pre>
<pre><span style=" font-family:'Courier New,courier';">//First a method to get an embedded connection:</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">public Connection getConnection() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        return DriverManager.getConnection("jdbc:derby:"+dbPath);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    } catch (SQLException e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">        return null;</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    }</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">//Now a method to start the server for external connections.</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">private void startDBServer() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		server = new NetworkServerControl(InetAddress.getByName("Localhost"),1527);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		server.start(null);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	} catch (Exception e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">//And lastly let's add a shudown hook to ensure the server gets a chance to exit clean.</span></pre>
<pre></pre>
<pre><span style=" font-family:'Courier New,courier';">private void setShutdownHook() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">	Runtime.getRuntime().addShutdownHook(new Thread() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">		public void run() {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			log.info("**** Application ending ****");</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			try {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				server.shutdown();</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				} catch (Exception e) {</span></pre>
<pre><span style=" font-family:'Courier New,courier';">					log.error(e.getMessage(),e);</span></pre>
<pre><span style=" font-family:'Courier New,courier';">				}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">			}</span></pre>
<pre><span style=" font-family:'Courier New,courier';">    } );</span></pre>
<pre><span style=" font-family:'Courier New,courier';">}</span></pre>
<pre></pre>
<p> That&#8217;s the basics and it doesn&#8217;t get much easier.</p>
Standard disclaimer - At the time of posting I believe  all information contained to be accurate but there is absolutely no warranty or guarantee.  ]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/combining-derby-embedded-mode-and-server-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brief introduction to Java Singleton Classes</title>
		<link>http://www.rogercuddy.com/programming/brief-introduction-to-java-singleton-classes/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.rogercuddy.com/programming/brief-introduction-to-java-singleton-classes/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 23:54:39 +0000</pubDate>
		<dc:creator>Roger Cuddy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.rogercuddy.com/brief-introduction-to-java-singleton-classes-17.htm</guid>
		<description><![CDATA[<p>The Singleton Pattern is quite simple but at the same time extremely useful. If you have done any serious programming then there is a good chance that you have fudged the behavior into a class or forced a class to act as a singleton without knowing the pattern. In this very short article we [...]]]></description>
			<content:encoded><![CDATA[<p>The Singleton Pattern is quite simple but at the same time extremely useful. If you have done any serious programming then there is a good chance that you have fudged the behavior into a class or forced a class to act as a singleton without knowing the pattern. In this very short article we will examine the common method to construct a singleton.</p>
<p><span id="more-17"></span></p>
<p>The main purposes of a singleton are to:</p>
<ul>
<li>Provide that only one instance of the class is created</li>
<li>Provide a single point of obtaining that instance</li>
</ul>
<p>The occasions where you want to ensure only one instance of a class are numerous and mostly obvious. Consider an application that performs many validation tests on a database and combines the results into a consolidated report. The simple way to consolidate the differing results is to allow each test to store it’s results into a central repository and then when desired the repository would combine the results and provide the formatted output. In such a situation you want only one instance of the result repository to exist so that all test results are stored in the same holding point.</p>
<p>The time honored method to provide a singleton is make the constructor non-public and provide a method called getInstance that returns the single instance of the class. Let’s look at how a simple singleton class achieves this.</p>
<pre>public class SimpleSingleton {
	private static SimpleSingleton instance = null;

	private SimpleSingleton(){}

	public synchronized SimpleSingleton getInstance() {
		if (instance == null) {
			instance = new SimpleSingleton();
		}
		return instance;
	}
}</pre>
<p>Some notes about derivations to this method. Obviously if you intended to subclass then the constructor must be protected instead of private. However if you make it protected it’s recommended that you put the class in it’s own package to prevent accidental access to the constructor from other classes in the package. Also it’s possible to reduce the overhead of the synchronization by syncing on the instance variable but in practice you won’t call getInstance enough to make it worth worrying about. Personally I recommend just taking the easy approach and creating a class variable at the top of each class that would access the singleton and saving all the method calls.</p>
<p>That’s it for the basics of singleton creation. There are numerous ways to expand on this simple example and we’ll cover several of them in an upcoming post.</p>
<p>For more coverage here are some selected readings on the singleton pattern:</p>
<p><a title="http://en.wikipedia.org/wiki/Singleton_pattern" href="http://en.wikipedia.org/wiki/Singleton_pattern">http://en.wikipedia.org/wiki/Singleton_pattern</a></p>
<p><a title="http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html" href="http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html">http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html</a></p>
<p><a title="http://blogs.techrepublic.com.com/programming-and-development/?p=449" href="http://blogs.techrepublic.com.com/programming-and-development/?p=449">http://blogs.techrepublic.com.com/programming-and-development/?p=449</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rogercuddy.com/programming/brief-introduction-to-java-singleton-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

