<?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>Kevin Grad &#187; java</title>
	<atom:link href="http://couchware.ca/www/kev/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://couchware.ca/www/kev</link>
	<description>Designer, Programmer and Co-Founder</description>
	<lastBuildDate>Fri, 30 Apr 2010 20:33:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Update: Wezzle, JavaEE 6 and beyond</title>
		<link>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/</link>
		<comments>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:13:59 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Wezzle]]></category>

		<guid isPermaLink="false">http://couchware.ca/www/kev/?p=171</guid>
		<description><![CDATA[Greetings Earthlings. 
It has come to my attention that I have not updated this blog in quite a while. This is an error that I wish to remedy immediately. Since my last post a lot of fun and exciting things have happened and I have learned a ton of new stuff that I will hopefully [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings Earthlings. </p>
<p>It has come to my attention that I have not updated this blog in quite a while. This is an error that I wish to remedy immediately. Since my last post a lot of fun and exciting things have happened and I have learned a ton of new stuff that I will hopefully write about in the near future.<br />
<span id="more-171"></span><br />
I would like to announce that <a href="http://couchware.ca/www/wezzle/">Wezzle </a>has been completed and is for sale on our website! It only took two years since Couchware&#8217;s inception, but it&#8217;s finally here and it looks great. I couldn&#8217;t be happier with the way Wezzle turned out. I think it looks outstanding and has some enjoyable and addicting game play. </p>
<p>I would like to give a huge thanks to those who assisted in the creation of the Wezzle. This includes Renee and Sam and all of our testers. If you like the art and music in the game be sure to check out <a href="http://www.reneelung.ca">Renee&#8217;s </a>and <a href="http://www.soundclick.com/bands/default.cfm?bandID=146918">Sam&#8217;s</a> websites. </p>
<p>Despite having put the game up for sale, Wezzle is not yet 100% complete. We are still hard at work finishing up a Wezzle demo that will be playable within the browser. Once the demo has been completed, we will be marketing/launching the game to a larger audience (hopefully!). There will likely be a launch party at an as of yet undisclosed location in Toronto. For those interested in coming, fire me an email or check back at this blog occasionally. Cam has also been hard at work at a REALLY cool Wezzle port, the nature of which I can&#8217;t disclose at the moment. It will be hopefully laying the ground-work for some of our future projects.</p>
<p>In other news, I have been put in charge of a major project using Java EE 6 which I&#8217;m pretty excited about.  Some of the technologies I have been using lately include: <a href="http://maven.apache.org/">Maven2</a>, <a href="http://logback.qos.ch/">Logback</a>, <a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/">JPA</a>/<a href="http://www.hibernate.org">Hibernate</a>, <a href="https://javaserverfaces.dev.java.net/">JSF</a>, <a href="http://java.sun.com/products/ejb/index.jsp">EJB 3.1</a>, and more. Hopefully in the coming weeks I will have something interesting to say about some of these. </p>
<p>Finally, I have bought kevingrad.com, org and net (all currently have no content) and I will eventually be moving this blog to one of those (probably .org).</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2010/03/01/update-wezzle-javaee6-and-beyond/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learning Scala</title>
		<link>http://couchware.ca/www/kev/2009/04/14/learning-scala/</link>
		<comments>http://couchware.ca/www/kev/2009/04/14/learning-scala/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 16:04:42 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[chapters]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[FP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[lift]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[smalltalk]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=152</guid>
		<description><![CDATA[My copy of Programming in Scala finally arrived yesterday, and I have had a chance to read the first chapter. It looks to be a very interesting language. I have had a desire to learn functional programming for a long time, and I have a giant fascination with programming languages in general. Scala seems to [...]]]></description>
			<content:encoded><![CDATA[<p>My copy of <a href="http://www.amazon.com/Programming-Scala-Comprehensive-Step-step/dp/0981531601/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1239717940&amp;sr=8-1">Programming in Scala</a> finally arrived yesterday, and I have had a chance to read the first chapter. It looks to be a very interesting language. I have had a desire to learn functional programming for a long time, and I have a giant fascination with programming languages in general. Scala seems to be getting a lot of hype right now, and the ability to program both <a href="http://en.wikipedia.org/wiki/Imperative_programming">Imperatively </a>and <a href="http://en.wikipedia.org/wiki/Functional_programming">Functionally </a>is too hard to pass up.<br />
<span id="more-152"></span><br />
Getting the book turned out to be more annoying than I had anticipated. The book is fairly new and as such, not yet available on <a href="http://www.chapter.ca">Chapters.ca</a>. It is available at <a href="http://www.amazon.ca">Amazon.ca</a>, however, the copy listed has a 2-3 week waiting period before shipping. I am an impatient person and I decided to order it from <a href="http://www.amazon.com">Amazon.com</a> because it listed the book as In Stock.</p>
<p>I placed the order on April 1, paying extra for the medium-tier shipping package so that I could get the book within 3-5 days of shipping. Since the book was in stock I was hoping to have the book by the end of the week. The only reason I ordered from the U.S. site (which obviously cost more for conversion, shipping, customs etc.) was so i could get the book without waiting 2-3 weeks. This prior weekend was a long weekend and it would have been nice to have had the book to read while I had some time at home. However, by April 8, the book still had not shipped. This was inconceivable to me as it was STILL listed as In Stock on their website, why would it not have shipped? </p>
<p>I sent a strongly worded letter to Amazon customer service, and to their credit, they upgraded me to premium shipping and sent it out the next day. The said there was a problem with the order that he fixed and sent it out at the next available opportunity. I highly doubt there was actually a problem other than the fact that I complained. Long story short, I finally have the book. Even though Amazon customer service was pretty good about the matter, I should not have had to contact them in the first place and I did not get to read the book over the long weekend as I had hoped.</p>
<p>Anyway, back to Scala. Scala seems to be a pretty cool language. From what I gather so far (and I will update you as I know more about it) it combines Object Oriented Programming (OOP) principles with Functional Programming (FP). It allows for both Imperative (think Java, C++) and Functional (Erlang, Haskell) programming styles. It is not the only language to do this, many languages provide functional programming features within the language, such as closures, functions as first class objects etc. The most notable languages to do this would be Python and Ruby.</p>
<p>However, Scala is not a dynamic language. It is statically typed, with type inference, which looks like it could be very nice. Additionally, Scala&#8217;s OO model is not implemented in a half-assed fashion like Java (primitives, statics, &#8230;) but rather, everything is an object (in the vein of Smalltalk, Ruby, etc.). Finally, it is lightweight, choosing to bundle most features in external libraries (comes with a standard library) rather than in the language itself, (such as BigIntegers, Actors).</p>
<p>The really interesting thing about Scala, is that it uses a lot of the Java types but extends them using something called Traits. For example, it uses primitive Java ints, but in order to make them objects, it defines a trait that will map Scala commands to a custom implementation (kinda). An example of this is if you want to call a function on an int, Scala will first look to the Java implementation, if the function doesn&#8217;t exist (which it wont because an int is a primitive) it will look to see if there are any traits defined, (which there are because its part of the Scala language) and then look for the function there. Scala uses these traits as means of wrapping the Java libraries in a nice way for use with the Scala language. It makes external libraries seem as if they are part of the Scala language, which is pretty nice. The beauty of this is, you can define your own traits and extend classes however you see fit. As well, you can use traits as lightweight interfaces, defining partial methods and enforcing multiple traits in a pseudo multiple inheritance scheme. Pretty powerful (if you understand what I just said anyway). I&#8217;m not 100% clear on traits so don&#8217;t get mad if some of the info I just mentioned is wrong.</p>
<p>Scala is also a fully functional language, borrowing some great ideas from other functional languages such as Haskell and Erlang. Of note, Scala uses an implementation of Erlang&#8217;s Actor&#8217;s shared memory model to accomplish parallel programming. Erlang&#8217;s model has been hugely successful and I am interested to see exactly how I can utilize this feature. </p>
<p>Scala&#8217;s name comes from &#8220;Scalable Language.&#8221; I&#8217;m not sure exactly what makes Scala so scalable, some of the things I&#8217;ve seen from my brief introduction is its use of traits, its integration with the Java standard library, its ability to run on the JVM and its Erlang-eque concurrency model. </p>
<p>There was a great question <a href="http://couchware.ca/blogs/cam">Cam</a> pointed out on <a href="http://stackoverflow.com/questions/648964/why-is-the-lift-web-framework-scalable">Stack Overflow</a> which talks a bit about what makes the <a href="http://liftweb.net/">Lift</a> web framework (written in Scala) so scalable. It is really interesting, and their take on threading is a good one in my opinion. Something I hope to maybe take advantage of with my own stuff.</p>
<p>I have to say that I am pretty excited to learn Scala. It seems like it could be a great language that is still undergoing heavy development and is very extendable. Ultimately I would like to combine Scala with some of my Java programming, something that I see as Scala&#8217;s (and all JVM languages) best feature. I believe this is still something that is not entirely EASY to accomplish. Something that I would like to see, and I am sure is on the list of things to do, is the ability to mix JVM languages transparently, without the need to call the specific compilers for the specific classes. Maybe I will work on that as a side project.</p>
<p>Scala is being touted by many as the next &#8220;Big&#8221; language. I don&#8217;t know if that&#8217;s necessarily the case, but it sure does seem like a nice language. Maybe it will quench my thirst for new languages temporarily? Who knows. I also purchased <a href="http://www.amazon.com/Programming-Language-Pragmatics-Third-Michael/dp/0123745144/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1239724031&amp;sr=1-1">Programming Language Pragmatics</a> with a mild desire to create my own language at some point. Perhaps I will be able to leverage some ideas from Scala when doing so.</p>
<p>This will be my first serious venture into the FP world (I have a little experience with Scheme, however, that was a long time ago, in a galaxy far far away&#8230;). I am already familiar with a bunch of functional techniques, such as closures/lambdas, but I have never really programmed in a functional way for something serious. Hopefully Scala turns out to be as nice as it appears to be, as I am excited to try the Lift framework and to start mixing functional programming with my current code.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/04/14/learning-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using custom attributes for validation</title>
		<link>http://couchware.ca/www/kev/2009/02/02/using-custom-attributes-for-validation/</link>
		<comments>http://couchware.ca/www/kev/2009/02/02/using-custom-attributes-for-validation/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 18:20:39 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[jquery]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[servlet]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=66</guid>
		<description><![CDATA[I was hired a couple of months ago to build a validation system for a legacy web-app built on Java Servlet technology. The app was a gigantic system with many existing web forms.

The job requirements included extendability, maintenance, minimal overhead, and it had to work with the current code, i.e. I couldn&#8217;t go and redesign [...]]]></description>
			<content:encoded><![CDATA[<p>I was hired a couple of months ago to build a validation system for a legacy web-app built on <a href="http://java.sun.com/products/servlet/">Java Servlet technology</a>. The app was a gigantic system with many existing web forms.</p>
<p><span id="more-66"></span></p>
<p>The job requirements included extendability, maintenance, minimal overhead, and it had to work with the current code, i.e. I couldn&#8217;t go and redesign the entire system. There were already hundreds of forms in the system with thousands of fields requiring validation. My first task was to explore the different possibilities. I came up with a few various schemes for both client side and server side validations. I opted to go with a client side solution for various reasons, including the fact that I could update the page with any error messages without ever needing to contact the server.</p>
<p>The major problem that I had to address was how to insert my validation functions within the already created web forms in an easy, extensible way. At the time I had been playing around with a JavaScript library known as <a href="http://jquery.com">jQuery</a>. I had very little experience with it, but it seemed very interesting. Cam had also recently begun using jQuery and was big on the library.</p>
<p>One of jQueries big features is easy manipulation of the DOM tree. jQuery ingeniously makes use of <a href="http://www.w3.org/TR/CSS2/selector.html">CSS Selectors</a> to wrap a group of elements in a jQuery wrapper. If you have never used CSS selectors, I HIGHLY recommend taking a look at them.</p>
<p>Using jQuery, the following simple code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:Consolas, monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.foo'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>returns an array of all DOM elements with the attribute class=&#8221;foo&#8221;. You can then iterate over this wrapped set in a number of ways. This is immensely powerful. Additionally, jQuery will recognize custom attributes.</p>
<p>The code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:Consolas, monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[required=true]'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>will return all input elements with a custom attribute required=&#8221;true&#8221;. What this means is, if you have in your HTML a text field like this:</p>
<p>&lt;input type=&#8221;text&#8221; required=&#8221;true&#8221;&gt;</p>
<p>The jQuery code above will find that element and return it in a wrapped jQuery array. I used this as the basis for my validation system.</p>
<p>What I did, was define a set of custom attributes, and a set of JavaScript functions based on requirements given to me by the hiring company. Then I created a validate() function which sequentially called all of my JavaScript functions. This validate function was meant to be called in an onSubmit() but could be called anytime.</p>
<p>If you ever wanted a field to be validated, you simply added my custom attributes to its HTML markup. So for example, if you wanted a field to be marked required, you simply went to that field and added required=&#8221;true&#8221;. If you wanted a field to be checked for a valid integer, you went to the field and added type=&#8221;integer&#8221;.</p>
<p>The beauty of this approach is that it allows a field to be marked with an arbitrary number of validations. And removing validation is as easy as removing the custom attribute. Additionally, if you add a new function to the set of JavaScipt functions, all you need to do to add it to a field is add the new custom attribute.</p>
<p>The way this works is, when the person submits the form, the validate function is called. The validate function uses jQuery to parse the DOM tree and iterate over the results. So within the validate function, the first function looked something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:Consolas, monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[required=yes]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>    
&nbsp;
  <span style="color: #006600; font-style: italic;">// validate the required strings.</span>
  <span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> validateRequired<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'field_name'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// If we had an error, concatenate it into the error string and add the errorCase</span>
  errorStr <span style="color: #339933;">+=</span> errorCheck<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>What this did was, it searched the page for any input elements with the custom attribute required=&#8221;yes&#8221;. It then iterated over that set and passed the value into the JavaScript function validateRequired() which checked whether the field was non-empty. It then returned an error string from a function that properly formatted error messages.</p>
<p>Each method concatenated an error string when there were any errors, and at the end of the validate() function if there were any error messages it printed them to the screen in a custom div. Otherwise, it allowed the submit to go through.</p>
<p>This was done for every type of validation, even if there was no elements with that custom tag within the current page. This makes it easy to simply add new validations on the fly. Also, all the JavaScript functions are in a central place and are easy to modify/update and have it filter through the system automatically.</p>
<p>This solution worked perfectly as it was easy to implement and fit the requirements perfectly. The client was pleased and everything worked out.</p>
<p>This may not be the way I would design the validation system today, but it was an excellent choice at the time.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/02/02/using-custom-attributes-for-validation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
