<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Dreams of a Rarebit Fiend</title>
      <link>http://www.johnmunsch.com/</link>
      <description></description>
      <language>en</language>
      <copyright>Copyright 2010</copyright>
      <lastBuildDate>Tue, 09 Mar 2010 18:10:33 -0600</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/?v=3.33</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
         <title>Bringing Unit Tests To Untestable Java Code</title>
         <description><![CDATA[<p>I deal with a lot of code that has never had any unit tests for it at all. In fact, it was often written in such a way that creating unit tests for it seems pretty horrific because you would find yourself having to load data into multiple database tables, set up all manner of services and files, etc. just in order to test it properly. So what I’m going to tell you is the simple, not-too-painful way I chose to make some of this code testable.</p>  <p>To me it’s all about removing all of the external dependencies from the code. If I can pull out all of the sections that are getting remote connections to EJBs, all of the data source lookups and queries, file reads, etc. and abstracting those out then I can test the code fairly easily because all I’ll be testing is the logic it had that surrounded all of those external calls to get data of one sort or another. So that’s what I do, I remove all of the code that does those lookups and abstract it out.</p>  <p>Note: <em>Some of the feedback I’ve gotten tells me that I should make it clear that what I’m talking about below is only the refactoring part of getting your code to a unit testable state. After you perform some of the steps you might be well placed to look into either Spring or JSR-299 (for example Weld, which is their reference implementation) to do dependency injection. Or even into mock frameworks to do simpler implementations of your FooHelper for testing purposes. If you’ve got one you like a lot, let me know about it. I haven’t used any mock libraries for Java yet.</em></p>  <p><strong>Step 1 - Use the refactoring capabilities in your IDE to extract some methods</strong></p>  <p>I’m using Eclipse in this example, but I’m sure you could do much the same thing in Netbeans or any other major IDE.</p>  <p>Eclipse has a function on the context sensitive menu to extract a method. Just select a section of the code that goes and looks up something in a file or gets a JDBC connection and executes a query (or calls some code that does) and click the right mouse button to get the context menu, then select Refactor &gt; Extract Method… and fill out the info in the dialog box where it asks you what to call your new method, etc. The refactoring will create an all new function which takes a set of parameters passed in and replace the code in the original spot with a call to that function. Repeat as needed on the offending section of code until you don’t have any code within it that isn’t actual logic that calls these new methods that use external resources.</p>  <p><strong>Step 2 – Pull the new methods out into an external class</strong></p>  <p>I don’t doubt that I could probably get Eclipse to do all of this too but at the moment I perform the next step manually.</p>  <p>Let’s say that the code that I was pulling methods out of was called foo(). Then I would create a new class called ProductionFooHelper at this point. I would pull all of the methods I extracted out of the class foo() was part of and put them into ProductionFooHelper(). That immediately breaks the foo() code because it no longer knows where the functions it used to call are anymore; but it leaves us with a version of foo that doesn’t require any exterior resources. That brings us to…</p>  <p><strong>Step 3 – Extract an interface from the ProductionFooHelper class</strong></p>  <p>Here Eclipse will do the tedious work for us again. Go to the ProductionFooHelper class and right click. Select Refactor &gt; Extract Interface… from the context menu that pops up.</p>  <p>You can just select all of the methods to be in the interface and give it a name like FooHelper. Click OK and it will be created. Note that ProductionFooHelper should be marked as implementing the FooHelper interface.</p>  <p><strong>Step 4 – Fix the failing calls within foo()</strong></p>  <p>Go back to the class containing the foo() code and add a new parameter to it. The new parameter would be something like “FooHelper helper”. Then all the function calls within foo() that are currently showing as errors within the IDE can have “helper.” put in front of them. That will indicate that we’re calling that function on the passed in class. At this point everything in the code should resolve again except for the spot you originally called foo(). It will need to have an instance of ProductionFooHelper created and passed into it before it compiles successfully.</p>  <p>At this point we’ve extracted all the code which had external dependencies into another helper class and we have a production version of that class that should give us the exact same behavior we’ve always had. But if we were to produce a MockFooHelper that implemented FooHelper and produced faked results for unit tests, then we could test foo() at our hearts content knowing that we never have to do database setup or anything else unless we want to. The specific implementation of the functions in the FooHelper is up to us for testing purposes.</p>  <p>This may seem a convoluted way to get to testable code and maybe you’ve got much better ways to achieve this same thing. If you do, I’d love to know about it so I can improve my own coding skills. But if not, I have to say that it actually works. I’ve used it recently in a hierarchical fashion where innermost code had a helper interface extracted, then another close to it, and then yet a third. Then I wanted code that called all of them to be unit testable so I extracted a new interface that implemented the other three interfaces and added all new functions as well. The production helper had all of the methods for the innermost stuff as well as the outermost. The result is that I now have four different test points in the code where I can control everything that goes in and out and I was able to whip off a dozen new tests for code that once had none due to its complexity and the difficulty of setting something up.</p>]]></description>
         <link>http://www.johnmunsch.com/2010/02/bringing_unit_tests_to_untesta.html</link>
         <guid>http://www.johnmunsch.com/2010/02/bringing_unit_tests_to_untesta.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Mon, 01 Feb 2010 14:00:33 -0600</pubDate>
      </item>
            <item>
         <title><![CDATA[Why Can&rsquo;t Java Do Convention Over Configuration?]]></title>
         <description><![CDATA[<p>I was just reading an <a href="http://java.sun.com/developer/technicalArticles/JavaEE/JavaEE6Overview.html">overview of Java EE 6</a> and I was struck by their handling of the web.xml file. In this article it is trumpeted as a great new feature, the monolithic web.xml file can now be chopped up into a set of files so you can group setup and configuration. And god knows, if there’s something you get a lot of in Java, it’s configuration.</p>  <p>Anyway, the heart of this is good, it’s in a good place. There’s no longer one big file, we can have several files and each one has its own purpose. You might even get a web.xml file that comes with some third party framework you’re using like Struts. However, then it starts to go off the rails (no pun intended):</p>  <blockquote>   <p>However, because Servlet 3.0 enables you to modularize your deployment descriptors, the order in which these descriptors are processed can be important. For example, the order in which the descriptors for an application are processed affects the order in which servlets, listeners, and filters are invoked. With Servlet 3.0, you can specify the order in which deployment descriptors are processed. </p>    <p>Servlet 3.0 supports absolute ordering and relative ordering of deployment descriptors. Your specify absolute ordering using the <code>&lt;absolute-ordering&gt;</code> element in the <code>web.xml</code> file. You specify relative ordering with an <code>&lt;ordering&gt;</code> element in the <code>web-fragment.xml</code> file.</p> </blockquote>  <p>Uh huh. When Rails (as in Ruby on Rails) needed to order a bunch of stuff like migrations, they made a simple convention (for example, 001_filename.rb, 002_filename.rb, 003_filename.rb). When that convention didn’t work out for large groups of developers they changed and went with the date and time instead (as in, 0080402122512_one.rb). Rails pretty much always picks a convention whenever possible and then if they need to they come up with a way to override it.</p>  <p>There’s nothing wrong with having &lt;ordering&gt; and &lt;absolute-ordering&gt; elements at all. Give the developer an override, fine, but give them an easy way to just name their stuff and order it automatically without that. What the heck is wrong with files named 001_web.xml and 200_web.xml? Seriously? Why can there never ever be a convention that the software reacts to and uses so you don’t have to hack up some configuration file 100% of the time?</p>]]></description>
         <link>http://www.johnmunsch.com/2009/12/why_cant_java_do_convention_ov.html</link>
         <guid>http://www.johnmunsch.com/2009/12/why_cant_java_do_convention_ov.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Thu, 31 Dec 2009 09:50:26 -0600</pubDate>
      </item>
            <item>
         <title>Hadoop And The Opposite Of The Not-Invented-Here Syndrome</title>
         <description><![CDATA[<p>Microsoft is famous for having a really bad case of&nbsp;'not-invented-here' syndrome. They don't like to accept any protocol or standard or even take a perfectly working piece of software and include it. It wasn't invented at Microsoft so it's automatically crap. They have to "fix it". Yahoo! appears to have turned that on its head.</p> <p>Yahoo's biggest competitor is arguably Google. Google invented an algorithm for data processing called <a href="http://labs.google.com/papers/mapreduce.html">MapReduce</a>. They use it to process the terabytes and petabytes of data they grind through on a regular basis.&nbsp;They piggy back that on top of their storage system called GFS (<a href="http://labs.google.com/papers/gfs-sosp2003.pdf">Google File System</a>). Because Google published papers on all this software, even though they don't make the software itself available, there was enough description for people&nbsp;to start developing their own versions of the Google tools.</p> <p>Yahoo has now decided to both use and endorse the toolset <a href="http://lucene.apache.org/hadoop/">Hadoop</a>. Hadoop encompasses implementations of both GFS and MapReduce so arguably Yahoo is now running software that is based on&nbsp;ideas from their&nbsp;direct competitor. They aren't shy about it either, they aren't hiding it, rather they are <a href="http://developer.yahoo.net/blog/archives/2007/07/yahoo-hadoop.html">telling the world that the software is good, they like it, and they intend to support it</a>.</p> <p>Bravo. I'm impressed.</p>]]></description>
         <link>http://www.johnmunsch.com/2007/08/hadoop_and_the_opposite_of_the.html</link>
         <guid>http://www.johnmunsch.com/2007/08/hadoop_and_the_opposite_of_the.html</guid>
         <category>Cool Links and Cool Software</category>
         <pubDate>Thu, 09 Aug 2007 12:55:41 -0600</pubDate>
      </item>
            <item>
         <title>A Follow Up On Sun&apos;s JavaOne Sessions</title>
         <description><![CDATA[<p>I mentioned the other day that Sun was making their JavaOne technical sessions available online and they have continued to upload more and more of the multimedia versions since then so you can listen to the audio while watching the synchronized slide presentation. In addition to that they've uploaded the instructions and materials from their <a href="http://developers.sun.com/learning/javaoneonline/j1labs.jsp?track=8&amp;yr=2007">hands-on labs</a> as well. If you'd like some in-depth step by step tutorials on a variety of different subjects then you should look through and see if any of them appeal to you. I spotted at least three that would be worth the time for me.</p>]]></description>
         <link>http://www.johnmunsch.com/2007/07/a_follow_up_on_suns_javaone_se.html</link>
         <guid>http://www.johnmunsch.com/2007/07/a_follow_up_on_suns_javaone_se.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Tue, 03 Jul 2007 09:59:55 -0600</pubDate>
      </item>
            <item>
         <title>JavaOne Sessions Available Free Online</title>
         <description><![CDATA[<p></p> <p>Sun is now making all their technical sessions from Java One available online. You can get the PDF for any of them and they are gradually getting the full audio plus slides&nbsp;up (e.g. all the 2006 presentations&nbsp;and about 20-25% of the 2007&nbsp;presentations&nbsp;are up in full audio/slides form now, the remainder of the 2007 stuff is PDF only for the moment). You have to join the Sun Developer Network (SDN) but signup for that is free.</p> <p><br><a href="http://developers.sun.com/learning/javaoneonline/">http://developers.sun.com/learning/javaoneonline/</a></p> <p>&nbsp;</p><a href="http://www.johnmunsch.com/WindowsLiveWriter/JavaOneSessionsAvailableFreeOnline_98DC/JavaOneSlideandAudioInterface1.png" atomicselection="true"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" src="http://www.johnmunsch.com/WindowsLiveWriter/JavaOneSessionsAvailableFreeOnline_98DC/JavaOneSlideandAudioInterface.png" width="240" border="0"></a>  <p>The presentations are pretty awesome. I'm watching the one on the Java Persistence API from 2006 and there are several others I have my eye on for later. This is an excellent educational resource and if you develop in Java for a living&nbsp;you would be remiss not to go through what's available there.</p>]]></description>
         <link>http://www.johnmunsch.com/2007/06/java_one_sessions_available_fr.html</link>
         <guid>http://www.johnmunsch.com/2007/06/java_one_sessions_available_fr.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Fri, 22 Jun 2007 10:56:13 -0600</pubDate>
      </item>
            <item>
         <title>Google Makes Their Internal Lectures Available To Anyone</title>
         <description><![CDATA[<p>Google&nbsp;has a regular&nbsp;internal lecture series&nbsp;on mostly technical topics with guest speakers and some of their own employees. This is their&nbsp;<a href="http://video.google.com/videosearch?q=engEDU">TechTalks Series</a>&nbsp;and the best part of it is that you and I&nbsp;can see them too. They record and digitize the talks (close to 300 of them to date) and make them available on Google Video, using a consistent tag on each one so you can easily search for them and see if any interest you. The link above will do the search and show you all the videos so far.</p> <p>Some of the titles that caught my eye:</p> <p><a href="http://video.google.com/videoplay?docid=2543830020407543872&amp;q=engEDU">Privacy Preserving DataMining</a></p> <p><a href="http://video.google.com/videoplay?docid=-985396858578246176&amp;q=engEDU">Turning Email Upside Down: RSS/Email and IM2000</a></p> <p><a href="http://video.google.com/videoplay?docid=5654878583447435228&amp;q=engEDU">Strike Up The Brand: How to Design for Branding</a></p> <p><a href="http://video.google.com/videoplay?docid=5225802147352970175&amp;q=engEDU">Ruby And Google Maps</a></p> <p><a href="http://video.google.com/videoplay?docid=-8103284744220333344&amp;q=engEDU">Ruby Sig: How To Design A Domain Specific Language</a></p> <p>Note: I'm not endorsing any of these, I haven't had a chance to view them yet. They just looked interesting to me.</p>]]></description>
         <link>http://www.johnmunsch.com/2007/02/google_makes_their_internal_le.html</link>
         <guid>http://www.johnmunsch.com/2007/02/google_makes_their_internal_le.html</guid>
         <category>Cool Links and Cool Software</category>
         <pubDate>Thu, 22 Feb 2007 15:54:39 -0600</pubDate>
      </item>
            <item>
         <title>How To: Overcome Being Regular Expression Challenged</title>
         <description><![CDATA[<p>I had never really learned regular expressions. Oh sure, I could use * and ? as well as the next guy, but throw [0-9]+ at me and I had no idea what it meant. That is, until the last year or so. Regular expressions can be very helpful in pattern matching against file names or user input and I dislike having gaps in the overall toolset of things I'm comfortable using.</p>

<p>So I set out to correct it. I'm still pretty ham-handed when it comes to typing in a regular expressions and I end up having to consult cheatsheets in order to remember the syntax to do a lot of things, but I discovered online tools and websites that helped me overcome the gap in my knowledge. Here are my favorites:</p>

<ul><li><a title="" href="http://www.txt2re.com/">txt2re: headache relief for programmers</a> - This lets you input a piece of text you want to match against using a regular expression and it displays different expressions you could use depending upon which parts you want to match against. It can give you a quick start on matching even if you aren't yet very regex savvy.</li><li><a title="RegEx: online regular expression testing" href="http://www.fileformat.info/tool/regex.htm">RegEx: online regular expression testing</a> - This is the other handy part of the equation. Here you can input several items of sample text and a regular expression you wish to test. Hit the test button and it will show you which test text matched, what parts were matched, etc. It's somewhat Java oriented but might be as useful for any language with fairly standard regex syntax. I've found it very helpful for iterative development of complicated regular expressions.</li><li><a href="http://regexlib.com/Default.aspx">Regular Expression Library</a> - A library of already crafted regular expressions (with various levels of complexity and robustness) to validate things like email addresses and telephone numbers.</li><li><a href="http://regularexpressions.info/tutorial.html">Regular Expression Tutorial</a> - A tutorial capable of teaching you enough to be dangerous in a fairly short time. Good info and it's not intimidating.</li>
</ul>]]></description>
         <link>http://www.johnmunsch.com/2006/12/how_to_get_past_being_regular.html</link>
         <guid>http://www.johnmunsch.com/2006/12/how_to_get_past_being_regular.html</guid>
         <category>Software Development</category>
         <pubDate>Mon, 18 Dec 2006 15:44:15 -0600</pubDate>
      </item>
            <item>
         <title>Sun Commits To Real Dates For Open Source Java</title>
         <description><![CDATA[<p>Why it isn't the biggest boldest headline on every major tech website is beyond me, but Sun has apparently commited to open sourcing the Java compiler (the part that takes Java source code and spits out Java byte code for VMs to run) and the HotSpot VM (an excellent virtual machine with really nice optimization) by the end of the year. They will also be open sourcing the Java Micro Edition (popular on cell phones and other small devices) and almost all the rest of the Java Standard Edition stuff by the first half of next year.</p>

<p>Oh, there's been talk about doing something for ages, but real action?!? Real dates with real pieces of software attached to the dates? Real dates that are in the near future?!? Wow! Simply WOW!</p>

<p>I've long argued that Sun was a company that did not <em>get</em> open source. Even though they had projects like NetBeans and OpenOffice, they frequently showed off a real ignorance of what we as Java users and they as Java owners stood to gain by making it all one big group effort. But when Jonathan Schwartz was put in as CEO there was a lot of talk about the fact that he <i>did get it</i>. Clearly the people who said that were right.</p>

<p>Expect Java's already huge lead on .NET to become insurmountable, this will likely be the final nail in the coffin for that particular mistake. Also expect to see releases of Java come much more frequently as we get group effort from corporations with a vested interest in Java throwing resources at it (i.e. IBM, BEA, Google, etc.).</p>

<p>More details are available in this article: <a title="Sun expands open-source Java plan | Tech News on ZDNet" href="http://news.zdnet.com/2100-3513_22-6105601.html">Sun expands open-source Java plan | Tech News on ZDNet</a></p>]]></description>
         <link>http://www.johnmunsch.com/2006/08/sun_commits_real_dates_for_ope.html</link>
         <guid>http://www.johnmunsch.com/2006/08/sun_commits_real_dates_for_ope.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Tue, 15 Aug 2006 12:34:57 -0600</pubDate>
      </item>
            <item>
         <title>This Just In: Sun Sacrifices Puppies</title>
         <description><![CDATA[<p>This just in, Sun sacrifices puppies to a pagan idol in order to try and regain market share and they also bundled a database with the upcoming JDK.</p>

<p>Reaction: <a title="Sun Bundles Java DB with Mustang b88 ..." href="http://www.javalobby.org/java/forums/t74408.html">OH MY GOD! They bundled a database! Kill it. Kill it with fire!</a></p>]]></description>
         <link>http://www.johnmunsch.com/2006/06/this_just_in_sun_sacrifices_pu.html</link>
         <guid>http://www.johnmunsch.com/2006/06/this_just_in_sun_sacrifices_pu.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Mon, 19 Jun 2006 16:02:12 -0600</pubDate>
      </item>
            <item>
         <title>Google Pulls Back The Curtain A Little More</title>
         <description><![CDATA[<p>Google used to be wrapped in mystery. Most developers knew little about how they do what they do. But over the last year or so they've been pulling back the curtain to reveal things like the Google File System, how they process enormous datasets, and in some cases even some details of what tools they are using to do things like Google Mail (Java, of course :) ).</p>

<p>They took that to its next level by releasing a beta version of a Java toolkit for Ajax work called the <a title="Google Web Toolkit" href="http://code.google.com/webtoolkit/">Google Web Toolkit</a>. It offers a lot of the same kind of remote procedure calls and DHTML/JavaScript stuff we've seen before in nifty toolkits like DWR except that this time I see just a few things I haven't seen elsewhere. One of those things is that when you do a web interface which has multiple tabs and you use their toolkit, you can actually bookmark individual tabs and even use next and previous in the browser correctly. This is something that is broken on many websites that use Ajax today.</p>

<p>I haven't put it to use yet but I will be trying it out in the future and comparing it to DWR unless someone else beats me to it.</p>]]></description>
         <link>http://www.johnmunsch.com/2006/05/google_pulls_back_the_curtain.html</link>
         <guid>http://www.johnmunsch.com/2006/05/google_pulls_back_the_curtain.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Fri, 19 May 2006 15:15:18 -0600</pubDate>
      </item>
            <item>
         <title>Showing Off Swing</title>
         <description><![CDATA[<p>I have liked Swing ever since I first used it. It makes far more sense than any of the Windows/GDI, X Windows, or Amiga UI work I had ever done in the past. It offers far more flexibility (often without a lot of pain) and I've never understood why anybody would be down on it other than because it has something of a learning curve associated with it. Nevertheless, it has gotten bashed because it is slow (I never thought so), ugly (can't agree), or just not cool enough.</p>

<p>Both of the latter two perceptions, I won't even refer to them as problems, are being addressed by people like Romain Guy who are working hard at technology demonstrations that show what Swing is really capable of and how cool and sexy it can be. If you want to see some pictures of the latest demonstration of what Swing is capable of, you can check out <a title="Aerith, a Very Cool Swing Demo" href="http://jroller.com/page/gfx?entry=aerith_a_very_cool_swing">Aerith, a Very Cool Swing Demo</a>. It features all kinds of 2D, 3D, and other effects to look like the latest thing from Apple.</p>

<p>Go there, check it out and maybe it'll influence you to try something in Swing that you might not have otherwise considered.<br />
</p>]]></description>
         <link>http://www.johnmunsch.com/2006/05/showing_off_swing.html</link>
         <guid>http://www.johnmunsch.com/2006/05/showing_off_swing.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Fri, 19 May 2006 10:35:17 -0600</pubDate>
      </item>
            <item>
         <title>Holding Off On Eclipse 3.2 Upgrade</title>
         <description><![CDATA[<p>I know a new release of Eclipse is coming soon. <a href="http://download.eclipse.org/eclipse/downloads/">Release Candidate 1 can be downloaded right now</a> for Version 3.2 if you are interested. But I have to confess I didn't have much of a clue what I was supposed to get in this release that would be different and worth upgrading for. After having looked through the documents below, detailing the new and notable changes for each milestone release up to today, I'm probably going to stick with 3.1.X for the moment and wait for the final release in June. This isn't the kind of major release that made an easy choice between learning Eclipse 2.0 or working with the milestone releases of 3.0, this is smaller incremental improvements befitting the minor version number increment it's getting.</p>

<ul><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M6-200603312000/eclipse-news-M6.html">Eclipse Platform 3.2 M6 New and Notable</a></li><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M5-200602171115/eclipse-news-M5.html">M5 New and Notable</a></li><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M4-200512151506/eclipse-news-M4.html">M4 New and Notable</a></li><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M3-200511021600/eclipse-news-M3.html">M3 New and Notable</a></li><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M2-200509231000/eclipse-news-all-M2.html">M2 New and Notable</a></li><li><a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.2M1-200508111530/eclipse-news-M1.html">M1 New and Notable</a></li></ul>]]></description>
         <link>http://www.johnmunsch.com/2006/04/holding_off_on_eclipse_32_upgr.html</link>
         <guid>http://www.johnmunsch.com/2006/04/holding_off_on_eclipse_32_upgr.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Tue, 18 Apr 2006 11:12:03 -0600</pubDate>
      </item>
            <item>
         <title>Tagged Code Snippet Repository</title>
         <description><![CDATA[<p>Peter Cooper has developed a <a href="http://www.bigbold.com/snippets/">simple source code snippet repository</a> with tagging that I like. It's far from perfect, the syntax highlighting is often squirrelly and if you enter in a multi-word tag like this "unit test" when you go to edit the code you get your tag back as two separate words so you always have to put the quotes back in place. Nevertheless, it works and it's a good start. Plus people aren't being shy about putting code out there.</p>

<p>What we need at this time are a small army of Java developers putting their code snippets into this repository. In no time it could be the place to go for a quick routine to fix a problem.</p>

<p>Here are my snippets thus far:<br />
<ul><li><a href="http://www.bigbold.com/snippets/posts/show/1600">Ant 101</a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1595">Getting A Data Source From Tomcat</a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1594">Data Source 101</a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1589">Velocity 101</a></li><li><a href=""></a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1592">Velocity 101 Unit Tests</a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1590">Email 101</a></li><li><a href="http://www.bigbold.com/snippets/posts/show/1591">Email 101 Unit Tests</a></li></ul></p>

<p>They will even give you <a href="http://www.bigbold.com/snippets/rss/user/JohnMunsch">a feed for when I post new snippets</a>. Unfortunately they don't have feeds for individual tags (e.g. Java) working yet. That's a shame and it's actually one of several glitches I've noticed. But even with the bugs this is still a more believable code snippet repository than many I've seen over the years. The tags go a long way towards making it really searchable and usable. But it will only be really useful if _everybody_ enters in some of their favorite utility functions and classes. So go sign up this minute and put in just three Java code snippets! It will take you less than 15 minutes and we will all benefit.</p>

<p>If there aren't any more improvements or he never releases the source code or it never gets full text search then maybe I'll move my snippets to another repository in the future. But it needs to be one with syntax highlighting, an easy framework for inserting the code in the first place (this is very very easy), and <em>tagging</em>.</p>]]></description>
         <link>http://www.johnmunsch.com/2006/02/tagged_code_snippet_repository.html</link>
         <guid>http://www.johnmunsch.com/2006/02/tagged_code_snippet_repository.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Tue, 28 Feb 2006 22:03:46 -0600</pubDate>
      </item>
            <item>
         <title>Upgrading The Ant In Anthill</title>
         <description><![CDATA[<p>Like many, I use UrbanCode's Anthill for automated builds. It's easy to setup, easy to run, and it has the basic features I need even in its open source version. But recently I noticed that it was ignoring failed builds and at first I couldn't figure out why. Everything else seemed to be working just fine and even installing the new Anthill 1.8.1 release didn't fix the problem.</p>

<p>Just in case you run into the same problem, it was due to me installing a new version of Ant (1.6.5 in this case) and the ant.bat file, which is what Anthill runs under Windows XP, not passing through the error code to Anthill. This <a href="http://lists.urbancode.com/pipermail/anthill/2005-December/003660.html">message from their mailing lists</a> a few months ago includes a replacement ant.bat file you can use and it will fix your problem.</p>]]></description>
         <link>http://www.johnmunsch.com/2006/02/upgrading_the_ant_in_anthill.html</link>
         <guid>http://www.johnmunsch.com/2006/02/upgrading_the_ant_in_anthill.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Fri, 24 Feb 2006 16:48:25 -0600</pubDate>
      </item>
            <item>
         <title>Quit Hardcoding Your *#%^ Database Connections!</title>
         <description><![CDATA[<p>Over and over I encounter Java code that <strong>hard codes</strong> database connection creation or resorts to pulling all of the connection parameters from a properties file bundled in with the .WAR or .JAR, or even a resource bundle (yes, that's you Kasai). QUIT IT!</p>

<p>There are these things in Java called data sources. They are an object you can go to and ask for a database connection, it hands it off, you use it to perform a query or two, you close it. That's it. If any database pooling, testing of new connections, etc. takes place it is hidden inside the data source and you don't have to think about it. In fact, because some data source implementions do things like pooling and testing of connections, they will probably work better than that five line version of "how to create a JDBC connection" you found online and pasted into your code.</p>

<p>Just about any type of server or framework you might choose to use around your application typically makes it easy to create data sources, specify all the details of how they connect to a database, and all you have to do is perform a couple of calls to get a data source. In the majority of your code, you don't even worry about the details of how the data source was obtained, you just accept it as one of the parameters to your class or to your method and you use it.</p>

<p>If your application isn't running inside a J2EE server, or Tomcat, or Spring, or some other place where a data source object is easy to come by, you can use the <a href="http://jakarta.apache.org/commons/dbcp/">Jakarta Commons DBCP</a> library to quickly create one of your own (hopefully configured using parameters that can be easily changed).</p>

<p>Here's an example of what I'm talking about that takes its configuration from system parameters:<br />
<code><br />
BasicDataSource dataSource = new BasicDataSource();</p>

<p>dataSource.setDriverClassName(System.getProperty("driverClassName"));<br />
dataSource.setUsername(System.getProperty("username"));<br />
dataSource.setPassword(System.getProperty("password"));<br />
dataSource.setUrl(System.getProperty("url"));<br />
</code></p>

<p>There you go, a data source that has caching and all kinds of other features you can tweak if you need them. Once you've got it you can call dataSource.getConnection() and out pops the connection ready to use. If you are running inside of Tomcat or WebLogic or something like that then you have even less of an excuse. In Tomcat for example, they provide a way to create data sources inside the Administration interface, you can just go to a web page, log in and create them. Retrieving one of the data sources you created in your code is this simple:<br />
<code><br />
// Obtain our environment naming context<br />
Context initCtx = new InitialContext();<br />
Context envCtx = (Context) initCtx.lookup("java:comp/env");</p>

<p>// Look up our data source by the name we gave it when we created it. In this case that's "jdbc/EmployeeDB".<br />
DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");<br />
</code></p>

<p>If you keep making everybody jump through hoops to set up your database connections when all we want to do is configure a data source, we'll just start rewriting your code. If you are writing a library to be used by other people, or an application that has to be configured by someone other than you, make it take a data source!</p>]]></description>
         <link>http://www.johnmunsch.com/2006/02/quit_hardcoding_your_database.html</link>
         <guid>http://www.johnmunsch.com/2006/02/quit_hardcoding_your_database.html</guid>
         <category>Software Development in Java</category>
         <pubDate>Tue, 14 Feb 2006 18:12:04 -0600</pubDate>
      </item>
      
   </channel>
</rss>
