<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4133036378510199203</atom:id><lastBuildDate>Mon, 07 Oct 2024 06:24:14 +0000</lastBuildDate><category>Java</category><category>.Net</category><category>Open Source Advocacy</category><category>Apple</category><category>Ruby</category><category>iPhone</category><category>misc</category><category>scala</category><category>Android</category><category>Java8</category><category>Linux</category><category>Microsoft</category><category>Sun/Oracle</category><category>groovy</category><category>humor</category><category>iPad</category><category>java scala groovy ruby clojure</category><category>java7</category><category>Clojure</category><category>Oracle/Apache Impasse</category><category>VirtualBox</category><category>fanboys of the world unite</category><category>howto</category><category>humor java javafx</category><category>humour opinion</category><category>javafx</category><category>patents</category><title>Dot Neverland</title><description>Ooh! lookie here, yet another tech blog...</description><link>http://dotneverland.blogspot.com/</link><managingEditor>noreply@blogger.com (julian_za)</managingEditor><generator>Blogger</generator><openSearch:totalResults>72</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-5382537418507728898</guid><pubDate>Mon, 06 Jun 2016 06:01:00 +0000</pubDate><atom:updated>2016-06-05T23:01:11.075-07:00</atom:updated><title>Swift for the Java Guy: Part 2 - The basics.</title><description>In Part 1 of this series we looked at how to get Swift up and running. In this part we will look the Differences between Java and Swift at a language level by creating the Swift classes and comparing them to Java. &amp;nbsp;For this article we will go over the basic of class construction.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Firstly; Whats the same.&lt;/h3&gt;
&lt;div&gt;
Both languages are fundamentally statically typed class based OO languages with single inheritance and interfaces. Furthermore Swift includes the normal set of features that Java has including:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Try-Catch style Exception handling&lt;/li&gt;
&lt;li&gt;C-Style syntax&lt;/li&gt;
&lt;li&gt;Generics&lt;/li&gt;
&lt;li&gt;First class and high order functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
Whats different&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Swift is very different in a key set of areas including&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Reference based memory management using Automated Reference counting as opposed to a garbage collector.&lt;/li&gt;
&lt;li&gt;Swift classes don&#39;t inherit from a base object class.&lt;/li&gt;
&lt;li&gt;Swift classes do not need to be declared in a file that follows the Namespace and Class name pattern.&lt;/li&gt;
&lt;li&gt;All methods in Swift are functions, Void in Swift is essential a type alias for an empty Tuple.&lt;/li&gt;
&lt;li&gt;Swift only has three access modifiers, private and public which behave similarly to the Java equivalents. It also has&amp;nbsp;&lt;i&gt;internal&lt;/i&gt;&amp;nbsp;which is Swifts equivalent of default access, Swift however has no protected modifier.&lt;/li&gt;
&lt;li&gt;Swift interface (or protocols as they are called in Swift parlance) cannot have default implementations (although you can achieve the same effect with extensions).&lt;/li&gt;
&lt;li&gt;Enums in Swift are &quot;different&quot;. The best way I can describe is that Swift Enums are basically a set named Tuples which are grouped together in a Enum declaration, each one can declare it&#39;s own structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
What Swift has that Java does not.&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Swift has a range of features that Java does not have&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Value Types (Structs)&lt;/li&gt;
&lt;li&gt;Tuples&lt;/li&gt;
&lt;li&gt;Extension types&lt;/li&gt;
&lt;li&gt;Operator overloading&lt;/li&gt;
&lt;li&gt;Type inference&lt;/li&gt;
&lt;li&gt;Language level optional monads and strict null checking&lt;/li&gt;
&lt;li&gt;Properties&lt;/li&gt;
&lt;li&gt;Destructors&lt;/li&gt;
&lt;li&gt;Values and variables as opposed to just variables ala Scala&lt;/li&gt;
&lt;li&gt;Nested functions (AKA functions inside functions)&lt;/li&gt;
&lt;li&gt;Pattern matching&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
Declaring your first Class in Swift&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
For this example I create simple class called &quot;Animal&quot; with a single void method makeSound&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(&quot;Roar!!&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;Animal().makeSound()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;A few observations:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Swift methods are explicitly declared with the&amp;nbsp;&lt;i&gt;func&lt;/i&gt;&amp;nbsp;keyword and have the return type after the &quot;-&amp;gt;&quot; operator which is the opposite order of Java approach in terms of declaration.&lt;/li&gt;
&lt;li&gt;The last line creates a new instance of&amp;nbsp;&lt;i&gt;Animal&lt;/i&gt;&amp;nbsp;and calls the&amp;nbsp;&lt;i&gt;makeSound&lt;/i&gt;&amp;nbsp;method. Note that Animal also has an implicit&amp;nbsp;&lt;i&gt;no-args constructor&lt;/i&gt;, also there is no&amp;nbsp;&lt;i&gt;new&lt;/i&gt;&amp;nbsp;keyword.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;
Adding a property&lt;/h3&gt;
&lt;div&gt;
So obviously not all animals roar, to fix this we add a property&amp;nbsp;&lt;i&gt;sound&lt;/i&gt;&amp;nbsp;to the class by adding the following&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; var sound:String = &quot;Croak&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(sound)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let animal = Animal()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;animal.sound = &quot;Roar&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;animal.makeSound()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
By default all variables (denoted by the&amp;nbsp;&lt;i&gt;var&lt;/i&gt;&amp;nbsp;keyword) declared as members are properties. What isn&#39;t visible here is that when you set the sound property it&#39;s actually accessed via accessor methods that are created implicitly. Another point worth mentioning is that the&amp;nbsp;&lt;i&gt;animal&lt;/i&gt;&amp;nbsp;variable is not a variable at all but rather a constant as indicated by the&amp;nbsp;&lt;i&gt;let&lt;/i&gt;&amp;nbsp;keyword, the&amp;nbsp;&lt;i&gt;let&lt;/i&gt;&amp;nbsp;keyword is Swift&#39;s equivalent of Scala&#39;s&amp;nbsp;&lt;i&gt;val&lt;/i&gt;&amp;nbsp;keyword.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Constructors&lt;/h3&gt;
&lt;div&gt;
In the previous example I set roar the default value of &quot;Croak&quot;, It would be better if we could pass this information via a constructor and make the sound property immutable, to do this we change the class as follows:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; let &amp;nbsp;sound:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; init(sound:String) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; self.sound = sound&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(sound)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let animal = Animal(sound:&quot;Roar&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;animal.makeSound()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Constructors in Swift are slightly different to Java in terms of syntax in that they are defined inside inside a block defined with the keyword&amp;nbsp;&lt;i&gt;init&lt;/i&gt;. These blocks can take parameters as you would have in a Java constructor. I also changed the sound property from&amp;nbsp;&lt;i&gt;var&lt;/i&gt;&amp;nbsp;to&amp;nbsp;&lt;i&gt;let&lt;/i&gt;, this means that the sound property cannot be reassigned once it&#39;s been assigned. Its also worth showing here that Swift requires you to use named parameters when you invoke the constructor, this will be familiar to anyone who has ever used Objective-C.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Adding an interface (or Protocol)&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
Since Animals aren&#39;t the only things that make sound, we can pull this functionality up into a Protocol called&amp;nbsp;&lt;i&gt;Audible&lt;/i&gt;&amp;nbsp;which can be implemented by the&amp;nbsp;&lt;i&gt;Animal&lt;/i&gt;&amp;nbsp;class.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;protocol Audible {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal:Audible {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; let sound:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; init(sound:String) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; self.sound = sound&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(sound)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let audible:Audible &amp;nbsp;= Animal(sound:&quot;Roar&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;audible.makeSound()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Here I added a protocol with a makeSound method, aside from the&amp;nbsp;&lt;i&gt;protocol&lt;/i&gt;&amp;nbsp;keyword, this should look familiar to most Java developers. The only change to the&amp;nbsp;&lt;i&gt;Animal&lt;/i&gt;&amp;nbsp;class is that it implements&amp;nbsp;&lt;i&gt;Audible&lt;/i&gt;. The syntax for extension and implementation is the colon syntax which works the same way as C#. I also explicitly typed my audible value to be of type&amp;nbsp;&lt;i&gt;Audible&lt;/i&gt;&amp;nbsp;just to force an upcast.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Properties on Protocols&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;With property properties onto Protocols. For this example I created another Protocol called&amp;nbsp;&lt;i&gt;Named&lt;/i&gt;&amp;nbsp;which just has a String property;&amp;nbsp;&lt;i&gt;name&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;protocol Named {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;var name:String {get set}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;protocol Audible {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;func makeSound() -&amp;gt; Void&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal: Audible, Named {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; let sound:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; var name:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; init(sound:String, name:String) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; self.sound = sound&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; self.name = name&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(sound)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;let animal &amp;nbsp;= Animal(sound:&quot;Roar&quot;, name:&quot;Lion&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;print(animal.name)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;animal.makeSound()&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
This example also shows mutability of the name property using the&amp;nbsp;&lt;i&gt;get&lt;/i&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;set&lt;/i&gt;&amp;nbsp;keywords. Interestingly I still have to define the actual name variable on the&amp;nbsp;&lt;i&gt;Animal&lt;/i&gt;&amp;nbsp;class. Keeping in mind that a Protocol defines behaviour, a property on a Protocol only indicates how the property is structured not how it&#39;s stored, that is the responsibility of the implementing class.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Inheritance&lt;/h3&gt;
&lt;div&gt;
For our final addition lets create a class called&amp;nbsp;&lt;i&gt;LivingOrganism&lt;/i&gt;&amp;nbsp;which implements&amp;nbsp;&lt;i&gt;Named&lt;/i&gt;&amp;nbsp;and make&amp;nbsp;&lt;i&gt;Animal&lt;/i&gt;&amp;nbsp;extend that. I also add a default constructor which takes the&amp;nbsp;&lt;i&gt;name&lt;/i&gt;&amp;nbsp;property as a parameter&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class LivingOrganism:Named &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;var name:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;init(name:String) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;self.name = name&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;class Animal: LivingOrganism, Audible {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; let sound:String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; init(sound:String, name:String) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; self.sound = sound&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; super.init(name:name)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; func makeSound() -&amp;gt; Void {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; print(sound)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Again note the C# style inheritance syntax. Another interesting thing to note is the use of the super keyword which behaves much like super in Java. In this case I invoked the super class init method inside Animal. One difference to Java is that Swift requires the local variables to be initialised first before invoking the super constructor, hence the call being the last line of Animal&#39;s constructor. This is the reverse of Java.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So there we have it, a basic overview of class construction in Swift. In the next part we will explore Some of the additional features of Swift such as Tuples and Strict Null checking with optional monads.&lt;/div&gt;
</description><link>http://dotneverland.blogspot.com/2016/06/swift-for-java-guy-part-2-basics.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-9178623233797960849</guid><pubDate>Sat, 28 May 2016 14:22:00 +0000</pubDate><atom:updated>2016-05-28T07:22:21.920-07:00</atom:updated><title>Swift for the Java guy: Part 1 - Getting Started</title><description>It&#39;s been a while since I had to look at the Apple development Eco-system.&lt;br /&gt;
&lt;br /&gt;
In fact the last time I did anything serious was back in 2009 when I tried to get in on the boom in apps at the time.&lt;br /&gt;
&lt;br /&gt;
I honestly didn&#39;t have a lot of issues with Objective-C as a language per se. In fact if anything I much preferred that than if I had had to whack out code in C or C++.&lt;br /&gt;
&lt;br /&gt;
I think my main objection - if I had one - was that the Xcode environment is nowhere close to the level of something like IntelliJ. Also the SDKs at the time were pretty limited compared to what you had on the full blown version of OSX.&lt;br /&gt;
&lt;br /&gt;
Needless to say; I spent a lot of time doing a lot more boilerplate code than what I would have liked.&lt;br /&gt;
&lt;br /&gt;
When Swift came out (almost two years ago now, can you believe it) I briefly looked at the language which I thought was quite nice but it didn&#39;t really interest me much. The biggest reason for this is that my world has been - for the most part - Server side Java running on some type *nix based platform.&lt;br /&gt;
&lt;br /&gt;
Fast forward two years and suddenly Swift is OSS and companies like IBM are trying hard to make Swift feature in my world.&lt;br /&gt;
&lt;br /&gt;
Ok but what can it do that Java cannot?&lt;br /&gt;
&lt;br /&gt;
Well here&#39;s a few things to consider:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Docker is changing the landscape in terms of how we deploy software. In a lot of ways Docker is the new Application server and the new virtual machine.&lt;/li&gt;
&lt;li&gt;Together with Docker we have the rise of Microservices and the need to create very small deployable units of code.&lt;/li&gt;
&lt;li&gt;Swift is a native language, it&#39;s fast out the box and incurs very little overhead in terms of memory and startup time.&lt;/li&gt;
&lt;li&gt;Swift is also a thoroughly modern and clean language.&lt;/li&gt;
&lt;li&gt;The combination of these things potentially makes Swift a great platform to build Dockerised Microservices, perhaps better than a language which historically incurs a large cost with it&#39;s VM and dependent libraries.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;br /&gt;&lt;/h3&gt;
&lt;h3&gt;
Installing.&lt;/h3&gt;
&lt;div&gt;
If you are you are using OSX the easiest way to get running is simply to get the latest version of Xcode from the App Store.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you are running &lt;b&gt;Ubuntu&lt;/b&gt; (14.04 or 15.04) I suggest you use the excellent&amp;nbsp;&lt;a href=&quot;https://swiftenv.fuller.li/en/latest/&quot;&gt;swiftenv&lt;/a&gt;&amp;nbsp;utility to install and manage Swift versions.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can also install swiftenv for OSX via Homebrew. This is useful if you want to easily play around with the Swift 3.0 development builds.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The system I am using for this post is running &lt;b&gt;Ubuntu 14.04&lt;/b&gt; and I using the 2016-05-09-a version which is a &lt;b&gt;Swift 3.0&lt;/b&gt; development snapshot.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Firstly I installed &lt;b&gt;swiftenv&lt;/b&gt; as follows:&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;git clone https://github.com/kylef/swiftenv.git ~/.swiftenv&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;echo &#39;export SWIFTENV_ROOT=&quot;$HOME/.swiftenv&quot;&#39; &amp;gt;&amp;gt; ~/.bashrc&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;echo &#39;export PATH=&quot;$SWIFTENV_ROOT/bin:$PATH&quot;&#39; &amp;gt;&amp;gt; ~/.bashrc&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;echo &#39;eval &quot;$(swiftenv init -)&quot;&#39; &amp;gt;&amp;gt; ~/.bashrc&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Then I can go ahead and install the Swift development package.&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;swiftenv install DEVELOPMENT-SNAPSHOT-2016-05-09-a&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
That&#39;s it! Swift is now installed.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can test the installation by running the &lt;a href=&quot;https://developer.apple.com/swift/blog/?id=18&quot;&gt;Swift REPL&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Building your first bit of Swift.&lt;/h3&gt;
&lt;div&gt;
My first issue that I encountered on Linux is the complete lack of a decent IDE for the Linux environment. For this example I ended up using good old Vim.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
However I&#39;m - somewhat ironically - playing around with &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;Visual Studio Code&lt;/a&gt; which also seems to do a decent job.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For this example I will do the obligatory &quot;Hello world&quot;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I simply create a file &quot;HelloWorld.swift&quot; and I put the following code in it.&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;print(&quot;Hello world&quot;)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And that&#39;s it. Swift will basically run any code which is declared inline alla Ruby, Python, Groovy et-al.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can now run this as follows:&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;swift HelloWorld.swift&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
at which point you see the output:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;hello world&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Wait a minute didn&#39;t I say this is compiled!?&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Another really neat feature of Swift is that you can run code both in interpreted and compiled mode.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To compile the code you simply run:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;swiftc HelloWorld.swift&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This spits out the Executable &quot;HelloWorld&quot; which you can simply execute as:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;./HelloWorld&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And there you have it! Swift is up and running. In the next post we will explore the language a bit.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Some Notes&lt;/h3&gt;
&lt;div&gt;
swiftc didn&#39;t work the first time on my machine. It turns out that Swift relies on a version 3.6 of Clang on Ubuntu 14.04&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I fixed this by doing the following:&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;apt-get install clang-3.6&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;update-alternatives /usr/bin/clang clang /usr/bin/clang-3.6 100&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;update-alternatives /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://dotneverland.blogspot.com/2016/05/swift-for-java-guy-part-1-getting.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-5590226662538306031</guid><pubDate>Wed, 25 Jun 2014 21:12:00 +0000</pubDate><atom:updated>2014-06-25T14:12:32.259-07:00</atom:updated><title>Type safe dependency injection using Java 8.0</title><description>So I sometimes really miss old school Dependency Injection. Back when Spring was still &quot;lightweight&quot; we happily configured all our beans in an &lt;i&gt;application.xml&lt;/i&gt;&amp;nbsp;file with the &quot;&lt;i&gt;learn-in-a-day&lt;/i&gt;&quot; Spring bean xml configuration. The downsides to this were of course a loss of type safety. I can think of quite a few test cases whose sole purpose was to bootstrap the Spring configuration file and just see if the &lt;i&gt;ApplicationContext&lt;/i&gt; starts up without going belly-up due to mis-wiring and correct resolution of included bean xml configuration files.&lt;br /&gt;
&lt;br /&gt;
I may be a minority but I never liked the Spring Schema configuration. To me it feels a bit like configuration for configuration.&lt;br /&gt;
&lt;br /&gt;
Annotations came along and improved things, with the caveat in that you have to import libraries for all those annotations. I like annotations but &amp;nbsp;there is a good case for having all your DI information in a central place so you can actually see how your app hangs together. Finally you sometimes need to create managed objects you can&#39;t annotate.&lt;br /&gt;
&lt;br /&gt;
Java Spring configuration makes things better with compile time safety, but I had to rethink the way I did a lot of my wiring, as I had to be careful how I did my wiring as I &amp;nbsp;lost some of the lazy eval that you get in a Spring context as your Java code evaluates immediately when the &lt;i&gt;ApplicationContext&lt;/i&gt; starts up.&lt;br /&gt;
&lt;br /&gt;
So, Java based DI is nice but how can we use Java 8.0 to improve it?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Apply that Lambda Hammer&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Right so this is the part of the post that starts applying the new hammer in Java 8.0: &lt;a href=&quot;http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html&quot;&gt;Lambdas&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Firstly Lambdas give a type safe way of deferring execution till it&#39;s needed.&lt;br /&gt;
&lt;br /&gt;
So, lets first create a wrapper object called &quot;ObjectDefinition&quot; who&#39;s job it is to define how an object should be created and wired with various values. It works by&amp;nbsp;instantiating the class we want to create and object from (In this case we have a class called &quot;&lt;i&gt;MyObject&lt;/i&gt;&quot;). We also give it a list of &lt;i&gt;&lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/util/function/BiConsumer.html&quot;&gt;java.util.function.BiConsumer&lt;/a&gt;&lt;/i&gt; interfaces which are mapped to a specific value. This list will be used to perform the actual task of setting values on the object.&lt;br /&gt;
&lt;br /&gt;
ObjectDefintion then instantiates the object using normal reflection and then runs though this list of BiConsumer interfaces, passing the the instance of the concrete object and the mapped value.&lt;br /&gt;
&lt;br /&gt;
Assuming we give our ObjectDefinition a fluent DSL we can do the following to define the object by adding the &lt;i&gt;set()&lt;/i&gt;&amp;nbsp;method which takes a BiConsumer and the value to set and populates the BiConsumer list as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&amp;nbsp; MyObject result = new ObjectDefinition&lt;myobject&gt;()
&lt;/myobject&gt;&lt;/code&gt;&lt;span style=&quot;font-family: monospace;&quot;&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; .type(MyObject.class)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; .set((myObject, value)-&amp;gt; myObject.setA(value), &quot;hello world&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: monospace;&quot;&gt;.set((myObject, value)-&amp;gt; myObject.setB(value), &quot;hallo welt&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; .create();&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
The &lt;i&gt;create()&lt;/i&gt;&amp;nbsp;method simply instantiates a&amp;nbsp;&lt;i&gt;MyObject &lt;/i&gt;instance&amp;nbsp;and then runs through the list of BiConsumers and invokes them passing the mapped value.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Method pointers??!! in Java??!! (Well Kinda)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
Now, Another interesting feature in Java 8.0 is Method references, which is a feature where the compiler wraps a method in a functional interface provided that that method can map to the signature of that functional interface.&lt;br /&gt;
&lt;br /&gt;
Method references allow you to map to an arbitrary instance of an object provided that the first parameter of that method is that instance value, and the subsequent parameters match it&#39;s parameter list.&lt;br /&gt;
&lt;br /&gt;
This allows us to map a BiConsumer to a setter where the first parameter is the target instance and the second parameter is the value passed to the setter:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp;MyObject result = new ObjectDefinition&lt;myobject&gt;()&lt;/myobject&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.type(MyObject.class)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.set(MyObject::setA, &quot;hello world&quot;)&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.set(MyObject::setB, &quot;hallo welt&quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.create();&lt;br /&gt;
&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;
Method references provide an interesting feature in that it provides a way of passing a reference to a method in a completely type safe manner. All the examples require the correct types and values to be set and the setter method needs to correspond to that type.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;It&#39;s Container Time&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So now we have &amp;nbsp;a nice little DSL for building objects, but what about sticking it into a container and allowing our ObjectDefinition to inject references to other values.&lt;br /&gt;
&lt;br /&gt;
Well, assuming we have this container, which conveniently provides a &lt;i&gt;build()&lt;/i&gt; method which provides a hook to add new ObjectDefinitions.&lt;br /&gt;
&lt;br /&gt;
We now have a container we can use to inject different objects in that container:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Container container = create((builder) -&amp;gt; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; builder&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .define(MyObject.class)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .set(MyObject::setA, &quot;hello world&quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;});&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;String myString = container.get(MyObject.class);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
Our Container object has the &lt;i&gt;define()&lt;/i&gt; method which creates an instance of an ObjectDefinition, which is then used to define how the object is created.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;But what about dependencies?&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Dependency Injection is no fun without being able to inject dependencies, but since we have a container we can now reference other objects in the container.&lt;br /&gt;
&lt;br /&gt;
To this end we add the &lt;i&gt;inject()&lt;/i&gt; method to our ObjectDefinition type, this can then be used to reference another object in the container by it&#39;s type:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp;Container container = create((builder) -&amp;gt; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; builder.define(String.class)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.args(&quot;hello world&quot;);&lt;br /&gt;
&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; builder.define(MyObject.class)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.inject(MyObject::setA,String.class);&lt;br /&gt;&amp;nbsp; &amp;nbsp;});&lt;br /&gt;&amp;nbsp; &amp;nbsp;MyObject myString = container.get(MyObject.class);&lt;/code&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In this example we map an additional object of type &lt;i&gt;String&lt;/i&gt; (the &lt;i&gt;args()&lt;/i&gt; method here is method which can map values to the the constructor of an object). We then inject this String calling the &lt;i&gt;inject()&lt;/i&gt; method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Cycle of Life.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
We can use the same approach of Lambdas and Method References to manage the life cycle of an object in the container.&lt;br /&gt;
&lt;br /&gt;
Assuming we want to run an initialisation method after all the values have been set, we simply add a new Functional interface which is invoked after all the values are set.&lt;br /&gt;
&lt;br /&gt;
Here we use the a &lt;i&gt;&lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html&quot;&gt;java.util.function.Consumer&lt;/a&gt;&lt;/i&gt; interface where the parameter is the instance we want to call the initialisation code on.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&amp;nbsp; &amp;nbsp; Container container = create((builder) -&amp;gt; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; builder.define(MyObject.class)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.set(MyObject::setA,&quot;hello world&quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.initWith(MyObject::start);&lt;br /&gt;&amp;nbsp; &amp;nbsp; });&lt;br /&gt;&amp;nbsp; &amp;nbsp; MyObject myString = container.get(MyObject.class);&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
In this example we added a &lt;i&gt;start()&lt;/i&gt; method to our MyObject class. This is then passed to the ObjectDefinition as a Consumer via the &lt;i&gt;initWith() &lt;/i&gt;method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Yet Another Dependency Injection Container&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
So all these techniques (and more) are included in the &lt;b&gt;YADI&lt;/b&gt; Container, which stands for &lt;b&gt;Y&lt;/b&gt;et &lt;b&gt;A&lt;/b&gt;nother &lt;b&gt;D&lt;/b&gt;ependancy &lt;b&gt;I&lt;/b&gt;njection &lt;b&gt;C&lt;/b&gt;ontainer.&lt;br /&gt;
&lt;br /&gt;
The code is available on Github at&amp;nbsp;&lt;a href=&quot;https://github.com/jexenberger/yadi&quot;&gt;https://github.com/jexenberger/yadi&lt;/a&gt;. And is licensed under an Apache License.&lt;br /&gt;
&lt;br /&gt;</description><link>http://dotneverland.blogspot.com/2014/06/type-safe-dependency-injection-using.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-1726024553190162216</guid><pubDate>Tue, 27 May 2014 20:34:00 +0000</pubDate><atom:updated>2014-05-27T13:34:41.450-07:00</atom:updated><title>When writing too much code can kill you</title><description>So now that I lured you in with that provocative title I suppose I need to clarify. Well it&#39;s true; too much coding can kill you, the real question is &quot;what is the reason?&quot; and the answer to that is; Chronic Stress.&lt;br /&gt;
&lt;br /&gt;
So why write about this; well it&#39;s personal. You see: it happened to me, and I&#39;m hoping to tell other people that it could happen to them to.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&quot;Holy Smokes Batman, do you mean it takes years&quot;&lt;/b&gt;&lt;br /&gt;
So what is Chronic stress.&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Chronic_stress&quot;&gt;To quote Wikipedia&lt;/a&gt;: Chronic stress&amp;nbsp; is the response to emotional pressure suffered for a prolonged period over which an individual perceives he or she has no control.&lt;br /&gt;
&lt;br /&gt;
A few key observations:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Chronic stress is prolonged stress experienced over a long time, period often years.&lt;/li&gt;
&lt;li&gt;There is a distinct physical effect on the body resulting in the continuous release of hormones meant to only be released for a temporary period of time.&lt;/li&gt;
&lt;li&gt;When you are in state of prolonged stress, you may not recognise it or if you do, feel that you cannot do anything about it.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&quot;Cortico...what!!??&quot;&lt;/b&gt;&lt;/div&gt;
The Human body is designed to deal with stress, provided it&#39;s temporary. When you are under stress your body releases hormones most notably Adrenalin and Cortisol. Adrenalin boosts your heart rate and energy supplies. Cortisol increases glucose in the bloodstream and increases the bodies ability to produce glucose and ability to repair tissue.&lt;br /&gt;
&lt;br /&gt;
If you were to compare is to a car, Cortisol is like Nitrous, Adrenalin is your Turbo.&lt;br /&gt;
&lt;br /&gt;
Now Nitrous is meant for a short boost, running it permanently is not &lt;a href=&quot;http://en.wikipedia.org/wiki/Nitrous#Reliability_concerns&quot;&gt;great for your engine&lt;/a&gt;. Adrenalin and Cortisol is pretty much the same. If you run it permanently &lt;a href=&quot;http://www.medicinegarden.com/2011/02/19/high-cortisol-ptsd-1/&quot;&gt;it&#39;s not great&lt;/a&gt; &lt;a href=&quot;http://www.adrenalfatigue.org/what-is-adrenal-fatigue&quot;&gt;for your body&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Here are a few highlights of what you might expect when you suffer from Chronic Stress.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Anxiety&lt;/li&gt;
&lt;li&gt;Irritability&lt;/li&gt;
&lt;li&gt;Recurring Insomnia&lt;/li&gt;
&lt;li&gt;Headaches&lt;/li&gt;
&lt;li&gt;Digestive disorders&lt;/li&gt;
&lt;li&gt;Depression&lt;/li&gt;
&lt;li&gt;Reliance on boosters such as caffeine&lt;/li&gt;
&lt;li&gt;Spikes and drops in energy at odd times&lt;/li&gt;
&lt;li&gt;Unexplained sudden weight gain&lt;/li&gt;
&lt;li&gt;Increase in illness and difficulty in recovering from illness&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
And (The ones that can kill you):&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Hypertension&lt;/li&gt;
&lt;li&gt;Cardiovascular disease.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
It&#39;s also worth noting that many of the symptoms have knock on symptoms.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For me particularly I started suffering from Insomnia almost a year and a half before I was diagnosed with Chronic stress. The effect this had quite a negative effect on my mood and concentration.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Developers are like &lt;a href=&quot;http://en.wikipedia.org/wiki/Soylent_green&quot;&gt;Soylent green&lt;/a&gt;.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
So Developers - contrary to popular belief - is people. In other words they are fallible limited creatures who have limitations in what they can do.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The problem is that we often subject ourselves to increased stress, because of crazy timelines, unrealistic expectations (both by our employers and also by ourselves) and no small amount of ambition.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This is complicated if you are a bit of an A-Type personality who has a tendency to take more and more things on.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The sad part is the more you take and the higher your stress levels become, the less productive you become.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The writing is on the wall&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
First chronic stress is not like a common cold, the symptoms develop after a long period of time and furthermore it&#39;s not something that really well understood.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The result is that it&#39;s that this type of thing that creeps up on you, and before you know it you are chronically stressed out and now you need treatment.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So here are some early warning signs that you can learn to identify it:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Recurrent episodes of insomnia.&lt;/li&gt;
&lt;li&gt;Multiple people repeatedly tell you: &quot;You look tired&quot; or something similar.&lt;/li&gt;
&lt;li&gt;Your buttons suddenly start being pushed often and you find yourself getting more easily aggravated at things.&lt;/li&gt;
&lt;li&gt;You start becoming very negative and people tell you as much.&lt;/li&gt;
&lt;li&gt;You suddenly realise you haven&#39;t engaged in a personal hobby or done something you like in quite some time.&lt;/li&gt;
&lt;li&gt;You often have a headache and/or heartburn.&lt;/li&gt;
&lt;li&gt;You struggle to turn off work and/or you&#39;re always anxious about a work.&lt;/li&gt;
&lt;li&gt;You often work overtime because it&#39;s the only time you can get &quot;flow&quot; due to the multitude of distractions in your environment.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;b&gt;Deal with it!&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
There is quite a lot help &lt;a href=&quot;http://www.helpguide.org/mental/stress_management_relief_coping.htm&quot;&gt;out there&lt;/a&gt;&amp;nbsp;with regards to reducing stress, but from a personal view there are a few things worth mentioning:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Ultimately no one actually forces you to be stressed out, If you don&#39;t find a way to deal with it no one else will.&lt;/li&gt;
&lt;li&gt;Other people won&#39;t get it or recognise it unless they have first hand experience, you have to accept and deal with it yourself.&lt;/li&gt;
&lt;li&gt;Acknowledge your limits.&lt;/li&gt;
&lt;li&gt;Take stress seriously, it can damage your relationships, your career and your health.&lt;/li&gt;
&lt;li&gt;Don&#39;t be afraid to get professional help.&lt;/li&gt;
&lt;li&gt;Take that vacation.&lt;/li&gt;
&lt;li&gt;Be careful when you blur work and pleasure, Especially if one of your hobbies is writing code.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
So I hope this was informative and here&#39;s hoping to no more stress and - off course - staying alive.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://dotneverland.blogspot.com/2014/05/when-writing-too-much-code-can-kill-you.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-7935822514996802261</guid><pubDate>Sat, 11 Jan 2014 15:01:00 +0000</pubDate><atom:updated>2014-01-11T07:02:05.143-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Java8</category><title>Builder pattern using Java 8</title><description>I work in an environment where a great deal of our day to day scripting tasks occur through calling remote services as opposed to working with the database.&lt;br /&gt;
&lt;br /&gt;
For a lot of scripting tasks I&#39;ve often used Groovy and one of the most useful features of Groovy specifically for that task has been it&#39;s built in fluent&amp;nbsp;&lt;a href=&quot;http://groovy.codehaus.org/Builders&quot;&gt;Builders&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Now Groovy builders exploit a few Groovy language features that are never going to make it into Java.&lt;br /&gt;
&lt;br /&gt;
Most notably Groovy builders make use of Groovy&#39;s Meta programming features which isn&#39;t coming to Java any time soon.&lt;br /&gt;
&lt;br /&gt;
However a key feature that Groovy builders have is their hierarchical approach to building constructs.&lt;br /&gt;
&lt;br /&gt;
This allows the builders to neatly and safely create nested tree like constructs which can be used to model everything from UX form layouts to XML.&lt;br /&gt;
&lt;br /&gt;
This approach we can at least model quite succinctly using Java 8 lambda expressions.&lt;br /&gt;
&lt;br /&gt;
For my sample I decided to take a reasonably simple Maven pom file and see if I could create a builder to handle that.&lt;br /&gt;
&lt;br /&gt;
All the code for the builder is available on Github &lt;a href=&quot;https://github.com/jexenberger/lambda-builder&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The pom.xml file is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVGpi_lkDh6BEZ7nBY39nsLI3YdejAQ6c_6RjCMjvL_QUPTZo71aRjLIgmWpXlbqkdGPudn9iWGzwLrgKR09wkzVJhnRZhjWh7laJwfso8X29176XotA_IHzwphgYwT7hXwJRqbgLSAVH3/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;  
 &amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;  
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;  
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&amp;gt;  
   &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;  
   &amp;lt;groupId&amp;gt;com.github&amp;lt;/groupId&amp;gt;  
   &amp;lt;artifactId&amp;gt;lambda-builder&amp;lt;/artifactId&amp;gt;  
   &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;  
   &amp;lt;dependencies&amp;gt;  
     &amp;lt;dependency&amp;gt;  
       &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt;  
       &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt;  
       &amp;lt;version&amp;gt;4.11&amp;lt;/version&amp;gt;  
     &amp;lt;/dependency&amp;gt;  
     &amp;lt;dependency&amp;gt;  
       &amp;lt;groupId&amp;gt;commons-beanutils&amp;lt;/groupId&amp;gt;  
       &amp;lt;artifactId&amp;gt;commons-beanutils&amp;lt;/artifactId&amp;gt;  
       &amp;lt;version&amp;gt;1.7.0&amp;lt;/version&amp;gt;  
     &amp;lt;/dependency&amp;gt;  
   &amp;lt;/dependencies&amp;gt;  
   &amp;lt;build&amp;gt;  
     &amp;lt;plugins&amp;gt;  
       &amp;lt;plugin&amp;gt;  
         &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;  
         &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;  
         &amp;lt;configuration&amp;gt;  
           &amp;lt;source&amp;gt;1.8&amp;lt;/source&amp;gt;  
           &amp;lt;target&amp;gt;1.8&amp;lt;/target&amp;gt;  
           &amp;lt;fork&amp;gt;true&amp;lt;/fork&amp;gt;  
           &amp;lt;compilerArgument&amp;gt;-proc:none&amp;lt;/compilerArgument&amp;gt;  
         &amp;lt;/configuration&amp;gt;  
       &amp;lt;/plugin&amp;gt;  
     &amp;lt;/plugins&amp;gt;  
   &amp;lt;/build&amp;gt;  
 &amp;lt;/project&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Here is the sample code for the builder to build this model:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVGpi_lkDh6BEZ7nBY39nsLI3YdejAQ6c_6RjCMjvL_QUPTZo71aRjLIgmWpXlbqkdGPudn9iWGzwLrgKR09wkzVJhnRZhjWh7laJwfso8X29176XotA_IHzwphgYwT7hXwJRqbgLSAVH3/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;     MarkupBuilder pom = new XmlMarkupBuilder(true, &quot;pom&quot;)  
         .at(&quot;xmlns&quot;, &quot;http://maven.apache.org/POM/4.0.0&quot;)  
         .at(&quot;xmlns:xsi&quot;, &quot;http://www.w3.org/2001/XMLSchema-instance&quot;)  
         .at(&quot;xsi:schemaLocation&quot;, &quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;);  
     pom.el(&quot;modelVersion&quot;, &quot;4.0.0&quot;);  
     pom.el(&quot;groupId&quot;, &quot;com.github&quot;);  
     pom.el(&quot;artifactId&quot;, &quot;lambda-builder&quot;);  
     pom.el(&quot;version&quot;, &quot;1.0-SNAPSHOT&quot;);  
     pom.el(&quot;dependencies&quot;, () -&amp;gt; {  
       pom.el(&quot;dependency&quot;, () -&amp;gt; {  
         pom.el(&quot;groupId&quot;, &quot;junit&quot;);  
         pom.el(&quot;artifactId&quot;, &quot;junit&quot;);  
         pom.elx(&quot;version&quot;, version::get);  
       });  
       pom.el(&quot;dependency&quot;, () -&amp;gt; {  
         pom.el(&quot;groupId&quot;, &quot;commons-beanutils&quot;);  
         pom.el(&quot;artifactId&quot;, &quot;commons-beanutils&quot;);  
         pom.elx(&quot;version&quot;, version::get);  
       });  
     });  
     pom.el(&quot;build&quot;, () -&amp;gt; {  
       pom.el(&quot;plugins&quot;, () -&amp;gt; {  
         pom.el(&quot;plugin&quot;, () -&amp;gt; {  
           pom.el(&quot;groupId&quot;, &quot;org.apache.maven.plugins&quot;);  
           pom.el(&quot;artifactId&quot;, &quot;maven-compiler-plugin&quot;);  
           pom.el(&quot;configuration&quot;, () -&amp;gt; {  
             pom.el(&quot;source&quot;, 1.8);  
             pom.el(&quot;target&quot;, 1.8);  
             pom.el(&quot;fork&quot;, true);  
             pom.el(&quot;compilerArgument&quot;, &quot;-proc:none&quot;);  
           });  
         });  
       });  
     });  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
A few notes on this in general:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;I created a special form of some the methods which takes a &lt;i&gt;java.util.function.Supplier&lt;/i&gt;&amp;nbsp;as a parameter, and allows you to delay evaluation of a value until you traverse the builder.&lt;/li&gt;
&lt;li&gt;I eschewed method chaining (although I catered for it in the builder). Trying both methods I personally felt this was a lot cleaner.&lt;/li&gt;
&lt;li&gt;Java doesn&#39;t have all syntax sugar that Groovy has, so I used a &lt;i&gt;java.lang.Runnable&lt;/i&gt;&amp;nbsp;for the functional interface which reduced the syntax creating a closure, with the downside that you have to have a handle on the initial builder object.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Nowhere as nice as Groovy builders but nevertheless a great step forward. Can&#39;t wait for Java 8.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://dotneverland.blogspot.com/2014/01/builder-pattern-using-java-8.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-8133049664891396823</guid><pubDate>Thu, 14 Nov 2013 16:04:00 +0000</pubDate><atom:updated>2013-11-19T22:15:52.795-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Java8</category><title>Adding Java 8 Lambda goodness to JDBC</title><description>Data access, specifically SQL access from within Java has never been nice. This is in large part due to the fact that the JDBC api has a lot of ceremony.&lt;br /&gt;
&lt;br /&gt;
Java 7 vastly improved things with ARM blocks by taking away a lot of the ceremony around managing database objects such as Statements and ResultSets but fundamentally the code flow is still the same.&lt;br /&gt;
&lt;br /&gt;
Java 8 Lambdas gives us a very nice tool for improving the flow of JDBC.&lt;br /&gt;
&lt;br /&gt;
Out first attempt at improving things here is very simply to make it easy to work with a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.sql.ResultSet.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here we simply wrap the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; iteration and then delegate it to Lambda function.&lt;br /&gt;
&lt;br /&gt;
This is very similar in concept to &lt;i&gt;Spring&#39;s JDBCTemplate&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NOTE:&amp;nbsp;&lt;/b&gt;I&#39;ve released All the code snippets you see here under an Apache 2.0 license on Github.&lt;br /&gt;
&lt;br /&gt;
First we create a functional interface called &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSetProcessor&lt;/b&gt;&lt;/span&gt; as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;@FunctionalInterface&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;public interface ResultSetProcessor {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void process(ResultSet resultSet,&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long currentRow)&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throws SQLException;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Very straightforward. This interface takes the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; and the current row of the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; &amp;nbsp;as a parameter.&lt;br /&gt;
&lt;br /&gt;
Next we write a simple utility to which executes a query and then calls our &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSetProcessor&lt;/b&gt;&lt;/span&gt; each time we iterate over the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;public static void select(Connection connection,&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String sql,&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ResultSetProcessor processor,&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Object... params) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try (PreparedStatement ps = connection.prepareStatement(sql)) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int cnt = 0;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (Object param : params) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ps.setObject(++cnt, param));&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try (ResultSet rs = ps.executeQuery()) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; long rowCnt = 0;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while (rs.next()) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; processor.process(rs, rowCnt++);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw new DataAccessException(e);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw new DataAccessException(e);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Note I&#39;ve wrapped the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;SQLException&lt;/b&gt;&lt;/span&gt; in my own unchecked &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;DataAccessException&lt;/b&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now when we write a query it&#39;s as simple as calling the select method with a connection and a query:&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;select(connection, &quot;select * from MY_TABLE&quot;,(rs, cnt)&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;-&amp;gt; { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(rs.getInt(1)+&quot; &quot;+cnt)&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;});&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
So that&#39;s great but I think we can do more...&lt;br /&gt;
&lt;br /&gt;
One of the nifty Lambda additions in Java is the new &lt;i&gt;&lt;a href=&quot;http://download.java.net/jdk8/docs/api/java/util/stream/package-summary.html&quot;&gt;Streams API&lt;/a&gt;.&lt;/i&gt; This would allow us to add very powerful functionality with which to process a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
Using the &lt;i&gt;&lt;a href=&quot;http://download.java.net/jdk8/docs/api/java/util/stream/package-summary.html&quot;&gt;Streams API&lt;/a&gt;&lt;/i&gt; over a ResultSet however creates a bit more of a challenge than the simple select with Lambda in the previous example.&lt;br /&gt;
&lt;br /&gt;
The way I decided to go about this is create my own &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Tuple&lt;/b&gt;&lt;/span&gt; type which represents a single row from a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
My &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Tuple&lt;/b&gt;&lt;/span&gt; here is the relational version where a Tuple is a collection of elements where each element is identified by an attribute, basically a collection of key value pairs. In our case the Tuple is ordered in terms of the order of the columns in the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
The code for the Tuple ended up being quite a bit so if you want to take a look, see the GitHub project in the resources at the end of the post.&lt;br /&gt;
&lt;br /&gt;
Currently the Java 8 API provides the&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.util.stream.StreamSupport&lt;/b&gt;&lt;/span&gt; object which provides a set of static methods for creating instances of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.util.stream.Stream&lt;/b&gt;&lt;/span&gt;. We can use this object to create an instance of a Stream.&lt;br /&gt;
&lt;br /&gt;
But in order to create a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Stream&lt;/b&gt;&lt;/span&gt; it needs an instance of &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.util.stream.Spliterator&lt;/b&gt;&lt;/span&gt;. This is a specialised type for iterating and partitioning a sequence of elements, the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Stream&lt;/b&gt;&lt;/span&gt; needs for handling operations in parallel.&lt;br /&gt;
&lt;br /&gt;
Fortunately the Java 8 api also provides the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.util.stream.Spliterators&lt;/b&gt;&lt;/span&gt; class which can wrap existing &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Collection&lt;/b&gt;&lt;/span&gt; and enumeration types. One of those types being a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;java.util.Iterator&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
Now we wrap a query and &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; in an Iterator:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;public class ResultSetIterator implements Iterator&lt;tuple&gt; {&lt;/tuple&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private ResultSet rs;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private PreparedStatement ps;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private Connection connection;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private String sql;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public ResultSetIterator(Connection connection, String sql) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assert connection != null;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assert sql != null;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.connection = connection;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.sql = sql;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void init() {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ps = connection.prepareStatement(sql);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rs = ps.executeQuery();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw new DataAccessException(e);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public boolean hasNext() {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (ps == null) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; init();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; boolean hasMore = rs.next();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!hasMore) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return hasMore;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw new DataAccessException(e);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private void close() {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rs.close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ps.close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //nothing we can do here&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SQLException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //nothing we can do here&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public Tuple next() {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return SQL.rowAsTuple(sql, rs);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (DataAccessException e) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw e;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
This class basically delegates the iterator methods to the underlying result set and then on the next() call transforms the current row in the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; into my &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Tuple&lt;/b&gt;&lt;/span&gt; type.&lt;br /&gt;
&lt;br /&gt;
And that&#39;s the basics done. All that&#39;s left is to wire it all together to make a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;Stream&lt;/b&gt;&lt;/span&gt; object. Note that due to the nature of a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt; it&#39;s not a good idea to try process them in parallel, so our stream cannot process in parallel.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;public static Stream&lt;tuple&gt; stream(final Connection connection,&amp;nbsp;&lt;/tuple&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;final String sql,&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;final Object... parms) {&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; return StreamSupport&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .stream(Spliterators.spliteratorUnknownSize(&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new ResultSetIterator(connection, sql), 0), false);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Now it&#39;s straightforward to stream a query. In the usage example below I&#39;ve got a table TEST_TABLE with an integer column TEST_ID which basically filters out all the non even numbers and then runs a count:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;long result = stream(connection, &quot;select TEST_ID from TEST_TABLE&quot;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .filter((t) -&amp;gt; t.asInt(&quot;TEST_ID&quot;) % 2 == 0)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .limit(100)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .count();&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
And that&#39;s it!, we now have a very powerful way of working with a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;b&gt;ResultSet&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
So all this code is available under an Apache 2.0 license on GitHub&amp;nbsp;&lt;a href=&quot;https://github.com/jexenberger/lambda-tuples&quot;&gt;&lt;b&gt;here&lt;/b&gt;&lt;/a&gt;. I&#39;ve rather lamely dubbed the project &quot;lambda tuples, and the purpose really is to experiment and see where you can take Java 8 and Relational DB access, so please download or feel free to contribute.</description><link>http://dotneverland.blogspot.com/2013/11/adding-java-8-lambda-goodness-to-jdbc.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-657184595743473494</guid><pubDate>Sun, 30 Dec 2012 19:00:00 +0000</pubDate><atom:updated>2012-12-30T11:00:05.309-08:00</atom:updated><title>New Years Resolutions for the Java Developer</title><description>So in closing on a rather eventful year for me personally it&#39;s always good to reflect and think and thus we apply the&amp;nbsp;cliché&amp;nbsp;of the new years resolutions - with a twist - in that they will be Geeky.&lt;br /&gt;
&lt;br /&gt;
So without further ado here we go.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Use Spring Less.&lt;/b&gt;&lt;br /&gt;
I plan to use vastly less Spring this year.&lt;br /&gt;
&lt;br /&gt;
Now Spring has pretty much become the de facto component framework in the Java ecosystem.&amp;nbsp;This is not a bad thing; that is until every software nail must be nailed flat with the Spring hammer.&lt;br /&gt;
&lt;br /&gt;
I been on the Spring Bandwagon now since about 2005 when Spring was still the breath of fresh air promising to save us from the evil Darth Ee-jay-bee. From about that time every developer with a glint in their eye and a will to type has tried to shoehorn everything to &quot;integrate&quot; into Spring.&lt;br /&gt;
&lt;br /&gt;
Again this is not necessarily bad, however I work for a company where the perception is that anything prefixed with the word &quot;Spring&quot; is automatically better, sometimes coming at the cost of something that is actually better.&lt;br /&gt;
&lt;br /&gt;
But lets not stop there...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;I&#39;m tired of the &quot;For Real?&quot; look I get from my developers when they are debugging Spring configuration and they ask my why Spring is better.&lt;/li&gt;
&lt;li&gt;I&#39;m tired of the massive War files I get and often the dependency clashes I have to fix because of the other stuff I need to pull in.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
So this new year I plan to use Spring in it&#39;s pure simple form.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Stop treating JPA/Hibernate as the one stop shop for Java based persistence.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
I want to use something besides JPA/Hibernate to do persistence this year, I want to do this because of the following:&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;I want to have POJOs that are still POJOs at runtime.&lt;/li&gt;
&lt;li&gt;I want to stop having weird hibernate exceptions that happen after we&#39;ve been in production for a bit, and then have my customer stop screaming at me.&lt;/li&gt;
&lt;li&gt;I want to stop having the rich domain model being so tantalisingly close to my grasp only to have it all come crashing down when the realities of ORM kick in.&lt;/li&gt;
&lt;li&gt;In reference to the previous point: I hate DAOs; JPA/Hibernate don&#39;t make them go away (at least not completely).&lt;/li&gt;
&lt;li&gt;I&#39;m tired of the &quot;For Real?&quot; look I get from my developers when they are debugging JPA/Hibernate issues and I&#39;m explaining to them how JPA/Hibernate simplifies things.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Now to fair a lot of the points listed is because JPA/Hibernate does a lot of complex heavy lifting on my behalf, but in many cases the power is just not needed.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Stop using Anonymous Inner classes and just bite the bullet and wait for 8.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
I&#39;ve been excited about the inclusion of closures in Java for a long, long time. I am a self confessed &quot;closurist &quot; and I fully plan to find as I many nails as I can when I get my closure powered hammer.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But I also have to accept that Java 8 especially in full production use is still going to be some ways away.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
And before that I resolve to resist the temptation to butcher code with anonymous inner classes in order to recreate that style of coding.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Stop worrying about the procedural code.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Hah! bet you never saw that one coming.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I&#39;ve been looking at the code that we produce, typically I do a lot of SOAP web services in my job, and what I see a lot of is that while we normally try to stick to SOLID principles, I don&#39;t see a lot of value coming out of the abstractions we create.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We have an&amp;nbsp;anaemic&amp;nbsp;domain model and most of the work is done in the Service tier implementation delegating to DAOs for data operations (although I&#39;ve started introducing newer patterns here).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I can&#39;t help feel that had I done this code in pure C it probably wouldn&#39;t feel massively different. To this end I sometimes wonder if all we do is procedural code with a bit of OO sauce on top.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I also wonder is this is necessarily a bad thing; the code works, it&#39;s simple to follow and read and is not burdensome to maintain, so this coming year I plan to to stop worrying about it :)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;/div&gt;
</description><link>http://dotneverland.blogspot.com/2012/12/new-years-resolutions-for-java-developer.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-7317970168834122586</guid><pubDate>Sat, 14 Jan 2012 15:06:00 +0000</pubDate><atom:updated>2012-01-14T07:06:39.666-08:00</atom:updated><title>Documentation that is useful</title><description>I was reading this &lt;a href=&quot;http://www.infoworld.com/d/application-development/how-get-developers-document-their-code-183908&quot;&gt;article&lt;/a&gt; by Neil Mcallister on his Fatal Exception blog entitled &quot;How to get developers to document their code&quot;.&lt;br /&gt;
&lt;br /&gt;
Now it begs the question: What documentation is actually useful?&lt;br /&gt;
&lt;br /&gt;
Well, like all things in general I don&#39;t think it&#39;s a simple answer, best I could say is; what works well in your context.&lt;br /&gt;
&lt;br /&gt;
In my personal context as a developer of information systems for commercial entities I personally find&amp;nbsp; the following useful when it comes to documentation:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;A decent setup and getting started guide: where to get the code, what tools and frameworks I need, how to build and configure it, and how to get it up and running.&lt;/li&gt;
&lt;li&gt;Environmental information regarding the various environments: How the development, testing, QA and production environments are accessed, configured and managed.&lt;/li&gt;
&lt;li&gt;A High level guide to how the components of the software fit together, with a one liner about what each component does.&lt;/li&gt;
&lt;li&gt;An High level ERD or any other high level domain model is also quite useful.&lt;/li&gt;
&lt;/ul&gt;Most of this documentation is really there to give context about the code, the rest I can figure out from the code itself.&lt;br /&gt;
&lt;br /&gt;
I also have a list of documentation that I think is a waste of time and effort:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; The above compiled into a document and then sent to die in something like Sharepoint: Useful documentation is easily searchable, easily accessible and easy to update referencing the actual models being used by architects and developers.&lt;/li&gt;
&lt;li&gt;Low level code documentation: It always out of date and rarely ever reflects the truth of the implementation to begin with (It&#39;s also annoying to read, Sequence diagrams come to mind). The only time documentation like this is useful is when the documentation effectively becomes the code (using MDA for example).&lt;/li&gt;
&lt;li&gt;Documentation done for the sake of process: No one will ever read this documentation except for the person who has to check that process is being followed. This seems to happen a lot in Waterfall environments where the process becomes so slow that organizations end up short circuiting pieces of the process in order to speed up development times. &lt;/li&gt;
&lt;/ul&gt;What do you consider useful in your context?</description><link>http://dotneverland.blogspot.com/2012/01/documentation-that-is-useful.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-4991242859779675215</guid><pubDate>Sun, 17 Jul 2011 18:16:00 +0000</pubDate><atom:updated>2011-07-17T11:16:43.825-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">java7</category><title>Java 8.0 Wishlist (Take 2)</title><description>Ok so it&#39;s it been a while since my last article on &lt;a href=&quot;http://dotneverland.blogspot.com/2011/04/java-80-wishlist.html&quot;&gt;this topic&lt;/a&gt;...&lt;br /&gt;
&lt;br /&gt;
The comments of course have been first rate, with opinions on the&amp;nbsp;wish-list&amp;nbsp;have ranged from outright agreement to threats of violence for even having such boneheaded ideas.&lt;br /&gt;
&lt;br /&gt;
It&#39;s all good of course, the thing that I love about the Java community is that we take the ideas and actually question them. Something I felt the .Net world could do more with.&lt;br /&gt;
&lt;br /&gt;
But anyway It&#39;s worth going through the list and giving a little rationale and meat on the wish-list, specifically on those that seemed to generate a lot of comments, so here goes...&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Properties.&lt;/b&gt;&lt;br /&gt;
Now I&#39;m going to debate the OO nature of properties. Fact is that - for better or for worse - JavaBean style properties have become baked into Java and it&#39;s frameworks. So why not at the bare minimum tell the compiler you want to generate getter and setter methods with syntax sugar. And yes IDE&#39;s generate this for you, but I&#39;d still prefer for the sake of brevity get rid of code that does stuff all.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Operator Overloading.&lt;/b&gt;&lt;br /&gt;
Easily the most contentious point. However let me give you my background: I recently did a lot of work doing monetary calculations. which &amp;nbsp;defined in an Excel spreadsheet by an Actuary. The only way I could get Java code to match the excel spreadsheet was to use ye olde BigDecimal. The code that came out is painful to say the least, mostly due to the lack of operators. Now BigDecimal is on the operator overloading todo list for Oracle, however it&#39;s painful having to wait, and the fact is that it&#39;s hard to build very expressive arithmetic types in Java.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Alternative deployment formats besides the JVM and &amp;nbsp;a classpath.&lt;/b&gt;&lt;br /&gt;
Ok this one seemed poorly presented. Basically I want to be able to compile a set of Java classes down into a native executable and deploy that. Even if all the executable does is wrap the classes together with a JVM. You ask why; that&#39;s easy I want to run Java apps on iOS.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Parameter names in method calls.&lt;/b&gt;&lt;br /&gt;
Ok so lets assume I have a method as follows:&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;public void crappyGFXtask(int startx, int starty, int secondx, int secondy, int lastx, int lasty)
&lt;/code&gt;&lt;/pre&gt;I dare you write the code to call it, leave it for a few days and then go back to it, and see if you can make sense of the parameters. Named parameters simply give you ability to map the parameter names to values ala Objective-C so your call to the method would look something along the lines of:&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;crappyGFXtask(startx:10, starty:11, secondx:25, secondy:40, lastx:myVariable, lasty:myVariable)
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Proxies on Abstract classes.&lt;/b&gt;&lt;br /&gt;
Yes Spring does this already, but guess what: I don&#39;t use Spring in every Java project I do (yes pigs are flying). It&#39;s a generally useful feature and JDK support would be sweet.&lt;br /&gt;
&lt;br /&gt;
Ok hope that clarifies things.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;</description><link>http://dotneverland.blogspot.com/2011/07/java-80-wishlist-take-2.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-1969813193088176438</guid><pubDate>Tue, 26 Apr 2011 20:43:00 +0000</pubDate><atom:updated>2011-04-26T13:43:14.857-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Java 8.0 Wishlist</title><description>With Java 7 almost out the door talk has now shifted to Java 8 and of course it&#39;s the perfect time for me to add my own $0.02 on my own wishlist.&lt;br /&gt;
&lt;br /&gt;
Properties.&lt;br /&gt;
Dunno what you can do here without annoying a few people. However I&#39;d happily settle for some type of shorthand notation for getters and setters.&lt;br /&gt;
&lt;br /&gt;
Operator overloading.&lt;br /&gt;
This one pops up at just about every Java release. Now it seems that there are plans in the works to add indexers to collections and such like. Quite frankly if you&#39;re gonna do that, why not add a full complement of fixed operator overloadings, maybe taking some ideas from how Groovy&amp;nbsp;&lt;a href=&quot;http://groovy.codehaus.org/Operator+Overloading&quot;&gt;does it&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Alternative deployment formats besides the JVM and a class path.&lt;br /&gt;
When you have to do one of those client Java applications that everyone claims nobody does, the Java deployment model really bites: Basically I want to create a fully contained application for a target platform. Now if all this contained application does at the end of the day is bootstrap a JVM together with a classpath who cares. It&#39;s also worth pointing out that this would allow Java applications to run quite easily on iOS, that is; if someone takes the time to do the port.&lt;br /&gt;
&lt;br /&gt;
Parameter names in method calls.&lt;br /&gt;
Nice to have, but it would make DSLs in java nicer.&lt;br /&gt;
&lt;br /&gt;
Finish Autoboxing.&lt;br /&gt;
I still can&#39;t do &lt;i&gt;1.toString().&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Proxies on Abstract Classes.&lt;br /&gt;
Not sure about the technical constraints on this, but it would be great if you could also create proxies on abstract classes and not just on interfaces.&lt;br /&gt;
&lt;br /&gt;
Make JavaFX useful.&lt;br /&gt;
Ok so JavaFX is not actually part of the JDK. Whatever the case, it&#39;s Oracle&#39;s chance to make client side Java really slick.&lt;br /&gt;
&lt;br /&gt;
Well that&#39;s my list for now...</description><link>http://dotneverland.blogspot.com/2011/04/java-80-wishlist.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-1109519889428242230</guid><pubDate>Fri, 18 Feb 2011 16:54:00 +0000</pubDate><atom:updated>2011-02-18T09:30:34.088-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">howto</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Using Google Contracts for Java with IntelliJ IDEA.</title><description>&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;span class=&quot;Apple-style-span&quot; &gt;The first step after obtaining the &lt;a href=&quot;http://code.google.com/p/cofoja/&quot;&gt;Google Contracts for Java&lt;/a&gt; &lt;a href=&quot;http://www.huoc.org/~minh/cofoja/&quot;&gt;Jar&lt;/a&gt; and adding it to your project, is to enable Annotation processing support in IDEA.&lt;/span&gt; &lt;/span&gt;&lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;To do this go to open the &lt;i&gt;Settings &lt;/i&gt;window (&lt;i&gt;IntelliJ IDEA &gt; preferences&lt;/i&gt; on Mac) and go to &lt;i&gt;Compiler &gt; Annotation Processors&lt;/i&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;Now do the following steps:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;&lt;/p&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; &quot; &gt;&lt;ul&gt;&lt;li&gt;Check the Enable Annotation processing option.&lt;/li&gt;&lt;li&gt;Select the Obtain processors from project classpath option.&lt;/li&gt;&lt;li&gt;In the Processed Modules table click the Add button and select the Module for which you want to enable Contracts for.&lt;/li&gt;&lt;li&gt;Hit Apply and you are ready to rock.&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgHbJLjrp3z4VevJedhJ5M8dhfm_cQD-L_5FcSwncWqw5DT-3cYxu6hnqHVZ_6f2i8XKZDmlibcfNsjb1TIbxavfJuFwKExRMR_J-5-v1ZjSEUuBQ2XCcgs_ap1b6GGGuJ0trupFkVx9A/s1600/Screen+shot+2011-02-18+at+7.10.01+PM.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 278px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgHbJLjrp3z4VevJedhJ5M8dhfm_cQD-L_5FcSwncWqw5DT-3cYxu6hnqHVZ_6f2i8XKZDmlibcfNsjb1TIbxavfJuFwKExRMR_J-5-v1ZjSEUuBQ2XCcgs_ap1b6GGGuJ0trupFkVx9A/s400/Screen+shot+2011-02-18+at+7.10.01+PM.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5575078016071633074&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;To test this you can add a basic contract annotation to a method in a class, here is one that I created using the &lt;b&gt;&lt;i&gt;@Requires&lt;/i&gt;&lt;/b&gt; annotation to ensure that the integer method parameter &quot;c&quot; has a value greater than zero:&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); line-height: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; overflow-x: auto; overflow-y: auto; width: 100%; &quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;import com.google.java.contract.Requires;&lt;br /&gt;&lt;br /&gt;public class TestSomeContracts {&lt;br /&gt;&lt;br /&gt;@Requires({&quot;c &gt; 0&quot;})&lt;br /&gt;public void testContract(int c) {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;Now when you compile you wont get much feedback as to wether the annotation was processed or not, as the contract syntax is correct, so lets modify it a bit to generate a compile splat by changing the variable name of the precondition:&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); line-height: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; overflow-x: auto; overflow-y: auto; width: 100%; &quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;@Requires({&quot;cs &gt; 0&quot;})&lt;br /&gt;public void testContract(int c) {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;When you build the module, you will now get a compilation failure which kinda integrates into IDEA, in that you can click on the error in the messages window and it will take you to the line that failed. Unfortunately IDEA wont highlight the line in your Editor or anything fancy like what you get in Eclipse, but it&#39;s good enough to work with.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgIvntQ8KBDjeD_51RFlmojyFL6kXjt4qif21-DAMeMaYGfMG8OhS32ydqLOUWfapjB6Cx7jji-udVhCSxw4kVT4TUuXjjThX2rCqmlpsr1O9hOBTofLSWhkG1c4B6hpMEl11MapuFSfA/s1600/Screen+shot+2011-02-18+at+7.17.36+PM.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 86px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgIvntQ8KBDjeD_51RFlmojyFL6kXjt4qif21-DAMeMaYGfMG8OhS32ydqLOUWfapjB6Cx7jji-udVhCSxw4kVT4TUuXjjThX2rCqmlpsr1O9hOBTofLSWhkG1c4B6hpMEl11MapuFSfA/s400/Screen+shot+2011-02-18+at+7.17.36+PM.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5575079803935662466&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p2&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;Using a class with contracts.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;After reverting and compiling the class I created a simple test case to test the contract by passing in data that violates the contract (ie. an integer less than 1):&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); line-height: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; overflow-x: auto; overflow-y: auto; width: 100%; &quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;br /&gt;import org.junit.Test;&lt;br /&gt;&lt;br /&gt;public class TestSomeContractsTest {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Test&lt;br /&gt;public void testContract() {&lt;br /&gt;  new TestSomeContracts().testContract(-1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;I&lt;span class=&quot;Apple-style-span&quot; &gt; run the test… and... it passes!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;In order to actually work, Google Contracts needs to do some bytecode shenanigans in order to actually enforce the contract definitions during runtime. Currently they have two modes of operation, an offline instrumenter which is a post compilation processor which weaves in the contracts into a compiled class, and a java agent.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;For development the most convenient method to use is the java agent.&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;To use the agent in IDEA, click the &lt;i&gt;Select Run/Debug Settings&lt;/i&gt; drop down and select the &lt;i&gt;Edit configurations&lt;/i&gt; option. Expand the &lt;i&gt;defaults&lt;/i&gt; entry and select the &lt;i&gt;JUnit&lt;/i&gt; option (or &lt;i&gt;TestNG&lt;/i&gt; or just plain &lt;i&gt;Application&lt;/i&gt;) and add the following to the &lt;i&gt;VM parameters&lt;/i&gt; field:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;          -javaagent:[path to the Google Contracts for Java jar file]&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;I Also remove an existing configuration so that it picks up the new option when I run the test again.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_328LT-6-9PqsOoRbi1HzpGLA2niI9y19AnTPG9gVy5qOjJn9y3gvn2Ewm-sKtOJOlx_maffX7KlREBHqt9OdvHRcGrQ70ReANnfA1q18jJt4rShkDLHi4JgWq2rw3rjeVpiaAc90mI/s1600/Screen+shot+2011-02-18+at+7.12.40+PM.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 331px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE_328LT-6-9PqsOoRbi1HzpGLA2niI9y19AnTPG9gVy5qOjJn9y3gvn2Ewm-sKtOJOlx_maffX7KlREBHqt9OdvHRcGrQ70ReANnfA1q18jJt4rShkDLHi4JgWq2rw3rjeVpiaAc90mI/s400/Screen+shot+2011-02-18+at+7.12.40+PM.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5575078542524752706&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;Now I run the test again and - voila - nice big splat when I run the test and pass invalid data to the method:&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-color: rgb(153, 153, 153); line-height: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; overflow-x: auto; overflow-y: auto; width: 100%; &quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; &gt;com.google.java.contract.PreconditionError: c &amp;gt; 0&lt;br /&gt;at TestSomeContracts.com$google$java$contract$PH$TestSomeContracts$testContract(TestSomeContracts.java:9)&lt;br /&gt;at TestSomeContracts.testContract(TestSomeContracts.java)&lt;br /&gt;at TestSomeContractsTest.testContract(TestSomeContractsTest.java:9)&lt;br /&gt;at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&lt;br /&gt;at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)&lt;br /&gt;at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)&lt;br /&gt;at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)&lt;br /&gt;at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)&lt;br /&gt;at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)&lt;br /&gt;at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)&lt;br /&gt;at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)&lt;br /&gt;at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)&lt;br /&gt;at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)&lt;br /&gt;at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)&lt;br /&gt;at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)&lt;br /&gt;at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)&lt;br /&gt;at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)&lt;br /&gt;at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)&lt;br /&gt;at org.junit.runners.ParentRunner.run(ParentRunner.java:236)&lt;br /&gt;at org.junit.runner.JUnitCore.run(JUnitCore.java:157)&lt;br /&gt;at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p class=&quot;p1&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  &gt;On a final note. Google contracts is still pretty fresh, so here&#39;s hoping IDE support will improve if the project takes off. I must also say that I&#39;m not too fond of the current mechanisms for enforcing the contract. Hopefully Google might take a page from Lombok and do to weaving at compile time.&lt;/span&gt;&lt;/p&gt;</description><link>http://dotneverland.blogspot.com/2011/02/using-google-contracts-for-java-with.html</link><author>noreply@blogger.com (julian_za)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgHbJLjrp3z4VevJedhJ5M8dhfm_cQD-L_5FcSwncWqw5DT-3cYxu6hnqHVZ_6f2i8XKZDmlibcfNsjb1TIbxavfJuFwKExRMR_J-5-v1ZjSEUuBQ2XCcgs_ap1b6GGGuJ0trupFkVx9A/s72-c/Screen+shot+2011-02-18+at+7.10.01+PM.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-3247537090326893020</guid><pubDate>Tue, 26 Oct 2010 08:17:00 +0000</pubDate><atom:updated>2010-10-26T01:34:18.563-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>Does Java need a &quot;Linux moment&quot;?</title><description>Does anyone remember that one of the reasons Linux or GNU/Linux (sorry Richard Stallman) was created, was to create a  Unix like environment which was free and open to use and not encumbered by the licensing restrictions of the AT&amp;amp;T&#39;s original Unix.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;With all the &lt;a href=&quot;http://www.jroller.com/scolebourne/entry/babylon_5_the_great_war&quot;&gt;stuff&lt;/a&gt; happening with Java right now, being a Java developer has become a depressing experience, and it&#39;s getting really hard to see a positives for the platform.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Perhaps Java needs it&#39;s own &quot;Linux moment&quot;. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A Java (but not Java) platform that is free and open and built on the same principles that made Linux a success, with the potential for the same type of success that Linux has enjoyed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I don&#39;t know if it&#39;s even feasible, but it&#39;s certainly becoming an appealing thought.&lt;/div&gt;</description><link>http://dotneverland.blogspot.com/2010/10/does-java-need-linux-moment.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-3000122295097467475</guid><pubDate>Thu, 07 Oct 2010 06:55:00 +0000</pubDate><atom:updated>2010-10-06T23:58:12.110-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">humor</category><category domain="http://www.blogger.com/atom/ns#">patents</category><title>Solving the software patent issue: The Software patent clearing house</title><description>&lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Motorola is suing Apple for infringing 18 of it&#39;s patents in it&#39;s phones and computers. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Apple is suing HTC for infringing it&#39;s patents.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Microsoft is suing Motorola for infringing its patents.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Nokia is also suing Apple, to which Apple countersued Nokia, all of course for patent infringements.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Lets not forget Oracle who is suing Google for infringing Java patents.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Now Microsoft is about to release it&#39;s Windows phone 7, and they&#39;ve had to do quite a bit of catchup so it&#39;s quite possible they might have &quot;infringed&quot; on some vague and obscure software patent. So it wouldn&#39;t surprise me if - in order to complete the circle of litigation - either an Apple or a Google type company sues Microsoft on or about the release date of Windows 7.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;It strikes me that all this circular ligation is forcing companies to spend an awful lot of money on lawyers who seem to be the only ones benefitting.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;To remedy this situation I recommend that it&#39;s time for a &lt;b&gt;Software patent clearing house&lt;/b&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Now what exactly would a Software patent clearing house do?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Basically it would be an organisation which has a central repository of all software patents. Whenever a company launches a software patent infringement suite against another company they would submit this suite to this organisation.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Since it&#39;s most likely that the company being sued would probably countersue with it&#39;s own patent infringement suite, The Software patent clearing house would be responsible for vetting and offsetting the patents of the first suite with the patents of the counter suite, and the only the company with a positive amount of patents left would be able to continue litigation.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;To illustrate: Let say company A sues company B for infringement of six of it&#39;s software patents. Company B could then countersue company A for infringement of four of it&#39;s patents. The clearing house would then subtract company B&#39;s claims from company A&#39;s claims, leaving Company A with two patent infringements it can litigate for.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;The clearing house could also provide a key additional service:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;You could do data mining on the patent information and create a &lt;b&gt;litigation index&lt;/b&gt; for companies which is basically a numerical value calculated to the perceived market value of the underlying patent. Companies with a low litigation index would have few patents while a company with many patents would have a high litigation index. Companies can then trade their litigation index points much like you could trade shares.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; font-style: normal; font-weight: normal; widows: 2; orphans: 2&quot;&gt; &lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;For example company A might have a high index but have a few bad quarters. They could then sell off index points (and consequently the patents backing the index points) which other companies could then buy bringing in cash for Company A. Company B who bought some index points can then use this index points to offset any patent litigation they might encounter, so if Company B get&#39;s sued by Company C they can use the index points to reduce the scale of the litigation, for example if they are being sued for infringement on six patents, they could trade off index points to the suing company to reduce the suite to a mere one or two patents. Company B could then even use it&#39;s own patent set to nullify the suite completely.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; widows: 2; orphans: 2&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-style: normal&quot;&gt;&lt;span style=&quot;font-weight: normal&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;The price of the index points would be determined by the availability of index points on the market against the volume of litigation. No doubt this price would become one the standard indicators that you normally get from financial news services.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; widows: 2; orphans: 2&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-style: normal&quot;&gt;&lt;span style=&quot;font-weight: normal&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Furthermore Venture Capitalists could even buy index points up front, which would become a regular part of the the capital that they provide new startups.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; widows: 2; orphans: 2&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-style: normal&quot;&gt;&lt;span style=&quot;font-weight: normal&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Some companies might even have so many index points they could get out of the software altogether and start simply start trading these index points as a means of making money.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; widows: 2; orphans: 2&quot;&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span style=&quot;font-style: normal; &quot;&gt;&lt;span style=&quot;font-weight: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;Of course the clearing house itself would need to charge fees in order to fund the operation, but think of what companies could save on legal fees, together with the allure of actually being able to earn cash of patents as opposed to getting into a major legal wrangling.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description><link>http://dotneverland.blogspot.com/2010/10/solving-software-patent-issue-software.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-1229870901638405176</guid><pubDate>Mon, 27 Sep 2010 06:19:00 +0000</pubDate><atom:updated>2010-09-26T23:29:23.749-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Clojure</category><category domain="http://www.blogger.com/atom/ns#">groovy</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Ruby</category><category domain="http://www.blogger.com/atom/ns#">scala</category><category domain="http://www.blogger.com/atom/ns#">Sun/Oracle</category><title>The Next Big Java Language; my $0.02</title><description>&lt;p style=&quot;margin-bottom: 0cm&quot;&gt;Time to to add my $0.02....&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;What is the &lt;b&gt;N&lt;/b&gt;ext &lt;b&gt;B&lt;/b&gt;ig &lt;b&gt;J&lt;/b&gt;VM &lt;b&gt;L&lt;/b&gt;anguage going to be?&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;I&#39;ve been watching the whole evolution of alternative languages on the JVM for a few years now. Long enough to start tracing the hype around the different languages.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;Yet none of these languages are really mainstream, despite their apparent advantages.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;I think the reason for this has absolutely nothing to do with the technical features (or lack thereof) of any of these languages.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;I think the NBJL will be the one that large organisation or group of organisations with enough clout and deep enough pockets is actually willing to go out and effectively market both to decision makers and developers.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;No doubt Java did strike a chord with mainstream developers, but quite honestly was that more to do with Sun&#39;s aggressive marketing campaign or because it of it&#39;s many technical merits?&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0cm&quot;&gt;&lt;br /&gt;&lt;/p&gt;</description><link>http://dotneverland.blogspot.com/2010/09/next-big-java-language-my-002.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-4880847237551242551</guid><pubDate>Mon, 23 Aug 2010 08:29:00 +0000</pubDate><atom:updated>2010-08-23T01:30:30.332-07:00</atom:updated><title>Quote of the Day</title><description>Quote of the Day:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&quot;In the end, any program must manipulate state.        A program that has no side effects whatsoever is a kind of black box.        All you can tell is that the box gets hotter.&quot;&lt;br /&gt;  &lt;br /&gt;            - Simon Peyton-Jones; Co-creator of the Haskell programming language.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;</description><link>http://dotneverland.blogspot.com/2010/08/quote-of-day.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-4348519257339297973</guid><pubDate>Sun, 15 Aug 2010 04:46:00 +0000</pubDate><atom:updated>2010-08-14T23:20:58.180-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.Net</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Why Java is more open than .Net</title><description>First of all, lets clarify a few things: Open does not necessarily mean free, and indeed Open Source, secondly in saying that Java is open, I also don&#39;t mean that it couldn&#39;t be more open than it already is and that the current processes don&#39;t have some painful problems regarding openness.&lt;br /&gt;&lt;br /&gt;With that out of the way, why is Java more open than .Net?&lt;br /&gt;&lt;br /&gt;Lets start with a Simple question: Can anyone show me a .Net 3.5 (Never mind .Net 4.0) &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;certified&lt;/span&gt; implementation, that also has &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;certified&lt;/span&gt; implementations of &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;all&lt;/span&gt; the important .Net technologies that actually make .Net useful  like WCF, WPF, WWF, WIF etc, etc. so that I can take my .Net 3.5 App written on Microsoft&#39;s .Net implementation and dump it unchanged onto this implementation onto - say Solaris - and it will run no problem regardless of what frameworks and features of those framework I used?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While you are looking it up, here are some more questions:&lt;br /&gt;&lt;br /&gt;&lt;li&gt;How do go about (or can I even) license .Net from Microsoft?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;How do I get a say in the specifications for new or existing .Net technologies?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Can I actually get my .Net implementation and appropriate frameworks rubber stamped by some certification authority?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Does .Net have some type of philosophy regarding platform neutrality?&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Here are the answers to those questions from a Java perspective:&lt;br /&gt;&lt;br /&gt;&lt;li&gt;I go to Oracle apply for a Java License, pony up some cash, agree to some terms, then I get a nice kit from Oracle and go forth an implement.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I join the Java Community Process and give input to the various Java Specification Requests, I can even submit new Java Specification Requests.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I run my implementation of a Java Specification Request against the Technology compatibility kit for that Java Specification Request and not I can say my implementation is certified.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Java has had the concept of Write Once Run Anywhere from the beginning and it&#39;s backed into Java and the JCP.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;So what does this mean, and why does it make Java more open?&lt;br /&gt;&lt;br /&gt;It means; that as an end user of Java I can pick and choose the best Java implementations around, and if I decide that I want to change the underlying platform or even the implementation I can do so with relatively little fuss.&lt;br /&gt;&lt;br /&gt;I have in the past run the same Java program happily on OSX, Windows, AIX on Solaris running on Intel, PowerPC and Sparc respectively.&lt;br /&gt;&lt;br /&gt;I have also developed on JBoss and deployed on Glassfish.&lt;br /&gt;&lt;br /&gt;In other words; &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;I as an end user am not locked into any specific Java provider&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;But what about &lt;span style=&quot;font-weight: bold;&quot;&gt;Mono&lt;/span&gt; and &lt;span style=&quot;font-weight: bold;&quot;&gt;Ecma&lt;/span&gt;?.&lt;br /&gt;&lt;br /&gt;Yes the CLR (and I think C# as well) is an Ecma standard which Java is not.&lt;br /&gt;&lt;br /&gt;But the CLR and C# alone maketh not a development platform and the stuff that makes .Net useful is not very open at all, and as much a &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://tirania.org/blog/archive/2010/Aug-13.html&quot;&gt;The Mono community likes to play it down&lt;/a&gt; a &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://blogs.computerworlduk.com/open-enterprise/2010/07/richard-stallman-on-net-mono-and-dotgnu/index.htm&quot;&gt;cloud still hangs over Mono regarding patents&lt;/a&gt;. (BTW: If any Mono guys  ever read this, it&#39;s fair to say that Mono hasn&#39;t cost Microsoft a lot so far, if Android where to run Mono, the cost to Microsoft might be in the billions, can you guarantee Microsoft&#39;s behavior when it&#39;s losing market share and money?)&lt;br /&gt;&lt;br /&gt;Things may of course change, Microsoft may actually put forward a formal licensing program, and together with the ECMA standardization, and then when I can run &lt;span style=&quot;font-weight: bold;&quot;&gt;all&lt;/span&gt; of .Net anywhere on any implementation, then I can say .Net is more open than Java.</description><link>http://dotneverland.blogspot.com/2010/08/why-java-is-more-open-than-net.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-7447634739078559729</guid><pubDate>Fri, 30 Jul 2010 06:12:00 +0000</pubDate><atom:updated>2010-07-29T23:52:43.324-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apple</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><title>Steve Jobs vs Steve Ballmer.</title><description>Ok, this time I really promise that this is the last I write about Apple for a while...&lt;br /&gt;&lt;br /&gt;This time however I&#39;m going to compare Steve Jobs and Steve Ballmer via the magic of &lt;a style=&quot;font-style: italic; font-weight: bold;&quot; href=&quot;http://www.youtube.com/&quot;&gt;Youtube&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Firstly lets compare the two men think about the nature of what a computer should be:&lt;br /&gt;&lt;br /&gt;Here&#39;s &lt;a style=&quot;font-style: italic; font-weight: bold;&quot; href=&quot;http://www.youtube.com/watch?v=ob_GX50Za6c&amp;amp;feature=related&quot;&gt;Jobs,&lt;/a&gt; now here&#39;s &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=VWkRgNTJZuM&quot;&gt;Ballmer&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now before I continue, it would be easy to write Steve Ballmer off, however during his tenure, Microsoft has become the &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.eweek.com/c/a/Cloud-Computing/Cloud-Awakens-Microsofts-Server-and-Tools-Giant-855303/&quot;&gt;most powerful technology company in the Enterprise&lt;/a&gt;. I daresay Ballmer&#39;s stoic approach to computing has allowed to see things in the black and white manner that Business customers understand.&lt;br /&gt;&lt;br /&gt;However is this a good thing. Does anyone remember how Microsoft got to the top? Bill Gates understood consumers, and that&#39;s how he drove Microsoft to the top. The question is does Ballmer &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=dR8SAFRBmcU&amp;amp;feature=related&quot;&gt;understand them.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now Steve Jobs is a character of note, and certainly not everbody&#39;s cup of tea. He&#39;s made some &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=dR8SAFRBmcU&amp;amp;feature=related&quot;&gt;nasty comments&lt;/a&gt; about Microsoft and actually seems &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=uqVt81XmKxc&quot;&gt;rather unfair&lt;/a&gt; if you ask me. But consider these interviews with Ballmer regarding Apple&#39;s &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=BcUicfqelC8&amp;amp;feature=related&quot;&gt;iPhone&lt;/a&gt;, &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=NZIOhFmJ8r8&amp;amp;feature=related&quot;&gt;AppStore&lt;/a&gt; and &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.youtube.com/watch?v=VWkRgNTJZuM&quot;&gt;iPad&lt;/a&gt;, just as they launched and then read &lt;a style=&quot;font-weight: bold; font-style: italic;&quot; href=&quot;http://www.theregister.co.uk/2010/07/29/ballmer_awake_at_night/&quot;&gt;this&lt;/a&gt;.</description><link>http://dotneverland.blogspot.com/2010/07/steve-jobs-vs-steve-ballmer.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-466767263163196997</guid><pubDate>Wed, 21 Jul 2010 18:27:00 +0000</pubDate><atom:updated>2010-07-22T05:51:34.875-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Android</category><category domain="http://www.blogger.com/atom/ns#">iPad</category><category domain="http://www.blogger.com/atom/ns#">Microsoft</category><title>Android and the iPad makes Steve Ballmer quiver in his boots.</title><description>I wonder if Android and the iPad keeps Steve Ballmer awake at night.&lt;br /&gt;&lt;br /&gt;Why so?&lt;br /&gt;&lt;br /&gt;The iPad is &lt;a style=&quot;font-style: italic;&quot; href=&quot;http://www.zdnet.com/blog/btl/apple-earnings-surge-jobs-says-amazing-new-products-still-on-tap/36959?tag=content;feature-roto&quot;&gt;successful&lt;/a&gt;, not only as a consumer device but also as an &lt;a style=&quot;font-style: italic;&quot; href=&quot;http://www.zdnet.com/blog/btl/apples-ipad-iphone-and-an-enterprise-halo-effect/36991?tag=content;feature-roto&quot;&gt;enterprise&lt;/a&gt; device. If the results of the iPad are anything to go by, the Tablet is poised to be a very popular form factor.&lt;br /&gt;&lt;br /&gt;But the iPad is effectively just one device (albeit the first one) in this new emerging Tablet space. It seems the &lt;a style=&quot;font-style: italic;&quot; href=&quot;http://www.google.com/search?q=Android+tablets&amp;amp;hl=en&amp;amp;prmd=nuisv&amp;amp;source=univ&amp;amp;tbs=nws:1&amp;amp;tbo=u&amp;amp;ei=tj5HTI7DHN6I4gav-qzZCQ&amp;amp;sa=X&amp;amp;oi=news_group&amp;amp;ct=title&amp;amp;resnum=1&amp;amp;ved=0CCoQsQQwAA&quot;&gt;majority&lt;/a&gt; of these devices will be running Android, and none seem to be running Windows.&lt;br /&gt;&lt;br /&gt;Now consider this. Windows has risen to be the dominant enterprise operating system, despite of the fact that for most of it&#39;s existence the Windows platform has been inferior to the Unix/Linux/Mainframe platforms.&lt;br /&gt;&lt;br /&gt;Consider how first DOS then Windows started out purely on - what was then - the low end of the computing market; the Desktop, and gradually started moving into more and more sophisticated applications, with each version getting incrementally better until Windows Server 2008, which can be used quite safely for high end computing tasks.&lt;br /&gt;&lt;br /&gt;It was able to do this, partly thanks to Moore&#39;s law but more importantly by capitalizing on the familiarity of Windows by the people making the decisions, not to mention the shallow learning curve offered to people who had practically grown up with the OS.&lt;br /&gt;&lt;br /&gt;Windows is an example of a &lt;a style=&quot;font-style: italic;&quot; href=&quot;http://en.wikipedia.org/wiki/Disruptive_technology&quot;&gt;disruptive technology&lt;/a&gt;, clearly illustrating the fact that&#39;s it&#39;s often easier to drive a low end product into the high end, than a high end product into the low end thanks to mass appeal.&lt;br /&gt;&lt;br /&gt;Unfortunately Windows is no longer a low end product.&lt;br /&gt;&lt;br /&gt;Windows 7 is optimized for desktops, it&#39;s not really designed for Tablets and touch screens, and so far it hasn&#39;t really featured much on any of the upcoming Tablets.&lt;br /&gt;&lt;br /&gt;Now iPad aside basically every new Tablet is running Android, a low end operating system and based on the iPad&#39;s success; the Tablet is the new &lt;a style=&quot;font-style: italic;&quot; href=&quot;http://en.wikipedia.org/wiki/Disruptive_technology&quot;&gt;disruptive technology&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So lets suppose for a minute that Android becomes the dominant Tablet OS, and that the Tablet becomes popular enough that at least most knowledge workers and decision makers have one.&lt;br /&gt;&lt;br /&gt;It&#39;s not inconceivable that those same knowledge workers and decision makers may easily decide to start using Android for other tasks, initially maybe for things like cheap Android powered terminals (even terminals calling Windows Apps via Citrix or Terminal services) for call center agents and then later for full desktop replacements.&lt;br /&gt;&lt;br /&gt;Now you may be thinking &quot;Huh! Android is a mobile OS&quot;  but consider that if it made the jump from a phone to a tablet, why couldn&#39;t it jump to a full desktop? I don&#39;t think many people envisaged Windows getting onto the server either.&lt;br /&gt;&lt;br /&gt;Of course this is just speculation, the only successful tablet so far is the iPad, and it&#39;s too early to say if any of the multitude of Android Tablets (most of which haven&#39;t even been released yet) will be as successful. Furthermore it&#39;s still early enough for Microsoft to develop a compelling product for the Tablet space.&lt;br /&gt;&lt;br /&gt;Microsoft - despite it&#39;s wide market range - Is dependent on it&#39;s desktop dominance. Steve Ballmer must be a very concerned man.</description><link>http://dotneverland.blogspot.com/2010/07/android-and-ipad-makes-steve-ballmer.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-8938532063376327308</guid><pubDate>Wed, 21 Jul 2010 18:06:00 +0000</pubDate><atom:updated>2010-07-21T11:22:29.807-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">VirtualBox</category><title>The power of simplicity.</title><description>Never underestimate the power of simplicity...&lt;br /&gt;&lt;br /&gt;I&#39;ve been running my Windows environment for work purposes on a Virtual Machine.&lt;br /&gt;&lt;br /&gt;I started off on Virtual Box and decided after a little while that I wanted to see what more sophisticated virtualisation would be like.&lt;br /&gt;&lt;br /&gt;My first attempt was Parallels 5. Now Parallels offers fantastic Integration, for example it wraps all the running Windows processes and presents them as processes running in your environment, so you can switch to VM applications as if they were running inside your host OS.&lt;br /&gt;&lt;br /&gt;The only problem was that Parallels is dead slow. It managed to grind my quad core i5 Macbook Pro to a halt, not to mention all the daemons it runs messes around with the startup and shutdown of the Macbook itself.&lt;br /&gt;&lt;br /&gt;My next attempt was VMWare Fusion. Now VMWare is the Mercedes Benz of virtualisation products, and although it wasn&#39;t as fancy as Parallels, it worked very well, easily reading and importing my existing virtual disks, and running the VM with little fuss and overhead with all the integration I really needed, without dragging down the performance of my Macbook.&lt;br /&gt;&lt;br /&gt;Unfortunately, on day three of my VMWare experiment I tried to restart a paused VM and it crashed and would not let me restart the OS inside the VM, I tried to reimport the original VirtualBox VM but it would not let me.&lt;br /&gt;&lt;br /&gt;So now I&#39;m back on VirtualBox. It&#39;s fast, simple and so far the only Virtualisation product I&#39;ve been able to use with any success.&lt;br /&gt;&lt;br /&gt;Bottom line: Simple is best.</description><link>http://dotneverland.blogspot.com/2010/07/power-of-simplicity.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-1215363588651161130</guid><pubDate>Tue, 13 Jul 2010 06:04:00 +0000</pubDate><atom:updated>2010-07-13T00:01:59.996-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Android</category><category domain="http://www.blogger.com/atom/ns#">Apple</category><title>Android vs Apple.</title><description>I don&#39;t think anyone who reads this blog will doubt the fact that I love Apple products. I write this blog entry on a Macbook Pro, I have an iPhone 3GS and before that I had the 3G which my wife is now very happy with.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I also like Android.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For me Android is best poised to become the commodity mobile platform for Phones and possibly for Tablets. It&#39;s going to become the DOS/Windows of the Mobile world.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I also like Android because of it&#39;s Open Source underpinnings and the Java roots of it&#39;s SDK.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;On top of that, I&#39;m also a Google fan, I use Chrome and I&#39;m watching the whole Google Wave thing with a lot of interest.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Furthermore besides the iPhone, I&#39;ve looked at developing some Android apps (An activity that is unfortunately limited because Google doesn&#39;t offer paid for apps in my country)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I even attempted to try buy an Android phone earlier this year. And I honestly couldn&#39;t find one that I liked (although that is mostly due to the rather poor selection we have in our Country)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The thing about Apple is that they build a device for which the software and hardware is in unison from the ground up, coupled with arguably the worlds best user experience.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For example, take OSX. OSX is a great product on it&#39;s own, and technically you could run it on a standard beige Intel box. The question is would I want to.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;OSX is the best part of my Macbook, but the sheer niceness of my Macbook hardware is enough to not make me want to run OSX on anything else. I would miss things like the integrated light sensors, the useable track pad, the lighted keyboard, the magnetic charger. Not to mention the eye soothing looks of the Unibody design.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There is however a problem with Apple&#39;s approach.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Apple provides the only way to use it&#39;s own products. In other words it&#39;s a pure product as opposed to being a platform like Android or Windows.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You can&#39;t build an &quot;ecosystem&quot; with Apple with new devices being used in new contexts, like embedding iOS into a robot or an industrial device like you could with Android.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;More importantly you will never be able to use Apple in a corporate for anything more than a niche group of users. The reason is quite simply that you can&#39;t run OSX on anything but Apple, and corporates don&#39;t like having thousands of desktops so tightly coupled to a single supplier.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As a result Apple is never going to be a monopoly in anything. A fact that is unfortunately baked into the way it does things.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I fully expect Android to product a market vastly larger and much more diverse than anything Apple could ever hope for.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I will even go so far as too say that Apple knows this and accepts it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So why am I writing this. Maybe because I don&#39;t like the fact that there is this belief in IT that for one platform to win the other has too lose. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It&#39;s the type of belief that allows monopolies to form and prosper.&lt;/div&gt;</description><link>http://dotneverland.blogspot.com/2010/07/android-vs-apple.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-2958494089570688858</guid><pubDate>Fri, 25 Jun 2010 18:11:00 +0000</pubDate><atom:updated>2010-06-25T11:58:50.001-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Sun/Oracle</category><title>Oracle and the Sun exodus</title><description>So Oracle has had quite a good quarter, with &lt;a href=&quot;http://www.businessweek.com/idg/2010-06-24/oracle-q4-profit-jumps-24-percent.html&quot;&gt;profit jumping 24%&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;What makes this interesting, is that Oracle claimed that $400 million worth of profit came from the sale of Sun gear, which is quite interesting especially that before the sale Sun hadn&#39;t really been making money even in the good times.&lt;br /&gt;&lt;br /&gt;At the same time James Gosling is &lt;a href=&quot;http://www.theserverside.com/news/thread.tss?thread_id=60436&quot;&gt;comforting &lt;/a&gt;the hordes of former Sun employees leaving Oracle.&lt;br /&gt;&lt;br /&gt;Quite honestly though, I think the whole exodus of Sun employees leaving is being overblown by the media.&lt;br /&gt;&lt;br /&gt;When you buy a company that is floundering like Sun was, you generally have to take drastic measures in order to bring that company back from brink, and drastic measures in the corporate world normally means doing lots of nasty things.&lt;br /&gt;&lt;br /&gt;Oracle has a reputation for being to integrate companies it purchases quite well, so it&#39;s therefore fair to say that they are pretty good at doing said nasty things.&lt;br /&gt;&lt;br /&gt;Now to take it a step further, Sun was not in a fantastic place when Oracle bought it, no doubt it needed some rather drastic measures to get things going again, so I can imagine Oracle had to do some &lt;em&gt;really nasty&lt;/em&gt; things.&lt;br /&gt;&lt;br /&gt;As a result you are going to get many people who leave, many of whom are good people who you don&#39;t want to lose, but it&#39;s unfortunately par for the course.&lt;br /&gt;&lt;br /&gt;To be totally honest It didn&#39;t even bother me when James Gosling left Oracle.&lt;br /&gt;&lt;br /&gt;Consider that he has pretty much had no publicly visible direct influence on core Java since it got handed over to the JCP which was 12 years ago.&lt;br /&gt;&lt;br /&gt;Now don&#39;t get me wrong, He&#39;s left a big hole in Java for Oracle, and I&#39;m hoping that he stays involved in Java, heck, maybe now he can contribute more directly to Java and the community than he could while he was working for Sun.</description><link>http://dotneverland.blogspot.com/2010/06/oracle-and-sun-exodus.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-3853522450726768953</guid><pubDate>Fri, 11 Jun 2010 05:15:00 +0000</pubDate><atom:updated>2010-06-10T22:52:42.738-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Oracle/Apache Impasse</category><title>A question for Oracle and the Apache Software Foundation</title><description>Time for a Rant.&lt;br /&gt;&lt;br /&gt;It&#39;s been roughly six months since Oracle bought Sun. And while I know very little about these things I doubt that it&#39;s been enough time to absorb a company like Sun whose product portfolio was extensive to say the least.&lt;br /&gt;&lt;br /&gt;For that reason I&#39;ve been pretty lenient on Oracle on the lack of information on Java that we developers have been getting.&lt;br /&gt;&lt;br /&gt;After reading &lt;a href=&quot;http://www.theregister.co.uk/2010/06/09/harmony_android_oracle_apache/&quot;&gt;this&lt;/a&gt; however, my mercy is exhausted. Basically Oracle and the Apache Software Foundation still haven&#39;t come to an agreement.&lt;br /&gt;&lt;br /&gt;In the mean time it sucks to be a Java developer right now. It&#39;s been three and half years since we had a new version of Java, and no new official version on horizon.&lt;br /&gt;&lt;br /&gt;I&#39;ve had more debates about &quot;what comes after Java&quot; in the past few months than in last 5 years.&lt;br /&gt;&lt;br /&gt;My question now to both Oracle and the ASF is this: What do you think the long term effect of this impasse is  going to be if you don&#39;t sort it, what value in Java are you destroying?</description><link>http://dotneverland.blogspot.com/2010/06/question-for-oracle-and-apache-software.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-8037552602187325109</guid><pubDate>Fri, 30 Apr 2010 06:39:00 +0000</pubDate><atom:updated>2010-04-30T00:00:39.987-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apple</category><category domain="http://www.blogger.com/atom/ns#">iPhone</category><title>Steve Jobs and the future of Apple.</title><description>Ok I promise this is the last blog on Apple for a while...&lt;br /&gt;&lt;br /&gt;Steve Jobs recently published an &lt;a href=&quot;http://www.apple.com/hotnews/thoughts-on-flash/&quot;&gt;article&lt;/a&gt; on Apples&#39;s web site detailing his reasons for why Flash is not allowed on the iPhone.&lt;br /&gt;&lt;br /&gt;The article has obviously taken quite a bit a bit of &lt;a href=&quot;http://www.osnews.com/story/23224/Jobs_on_Flash_Hypocrisy_So_Thick_You_Could_Cut_it_with_a_Knife&quot;&gt;flak&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here&#39;s the thing though, much as everyone decries Apple, they tend to forget that Apple is not a monopoly in any market that it operates, and they can&#39;t force anyone to buy their products.&lt;br /&gt;&lt;br /&gt;This is important because if Apple manages to annoy enough developers and users, there are sufficient alternatives in the market to Apple products to allow said users and developers to leave.&lt;br /&gt;&lt;br /&gt;If this happens then it&#39;s fair to say that the only entity that is going to suffer in this mess is Apple itself.</description><link>http://dotneverland.blogspot.com/2010/04/steve-jobs-and-future-of-apple.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-4933888136118793648</guid><pubDate>Fri, 29 Jan 2010 17:47:00 +0000</pubDate><atom:updated>2010-01-29T11:46:27.730-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apple</category><category domain="http://www.blogger.com/atom/ns#">iPad</category><category domain="http://www.blogger.com/atom/ns#">iPhone</category><title>A few thoughts on the iPad</title><description>Being the resident Mac fan I thought I might add my $0.02 on the iPad.&lt;br /&gt;&lt;br /&gt;Firstly the name is aweful, I can&#39;t believe that someone didn&#39;t start giggling the moment the suggestion was made. I have two theories about how this one got through; 1) The obvious : Steve Jobs made the suggestion therefore it was so. Or 2) The marketing guys were stereotypically stoned so that means a) no one thought much about the giggling and b) they were - well - stoned.&lt;br /&gt;&lt;br /&gt;Secondly, yes, it is a large iPhone. Rumor has it that the iPad design has gone back and forth between the drawing board and prototype stage a couple of times, in fact it&#39;s technologies became the basis of the iPhone, Now the leaked sources pretty much confirmed that the iPad was going to be using the iPhone OSX as a basis so the way the OS looks and works was not at all surprising, but I&#39;m rather dissapointed that Apple chose to so blatantly follow the physical look of the iPhone, after all, it is a design which - while being very pretty - is getting on in the years. Now it was probably too late by then, but I hope Steve is going &quot;Oh crap why didn&#39;t we think of that&quot; when he watched Avatar.&lt;br /&gt;&lt;br /&gt;Thirdly it&#39;s not an iPhone at all. If you drill down into this logic you can quite easily make that argument that my laptop shares many of the characteristics of my iPhone by virtue of the fact that both can perform many of the same functions.&lt;br /&gt;&lt;br /&gt;So what is the iPad then, it&#39;s not a laptop, it&#39;s not a netbook, it&#39;s not a phone, it&#39;s also nothing at all like Bill Gate&#39;s vision for the tablet PC way back in 2001.&lt;br /&gt;&lt;br /&gt;The fact is that the iPad simply doesn&#39;t fall into any of the current categories, Apple has the rather daunting task of trying to create a completely new class of mobile device.&lt;br /&gt;&lt;br /&gt;This is both a blessing and a curse.&lt;br /&gt;&lt;br /&gt;If the iPad takes off, it will be great for Apple of course, being the pioneers in a new category, the problem of course is that in order for this new category to take off you need to have customers who have a reason to buy one.&lt;br /&gt;&lt;br /&gt;In other words you need a killer application.&lt;br /&gt;&lt;br /&gt;Now with that in mind here are a few things to ponder:&lt;br /&gt;&lt;br /&gt;The starting price is $499, which will translate into about +- R5500 after import duties (unless the importers decide to milk us dry). This makes it cheaper than many smartphones including HTC&#39;s Android phones. It also falls in the same pricing bracket as many Netbooks.&lt;br /&gt;&lt;br /&gt;It has quite an awesome battery life, You could use this device for most of the day, no boot up time and no hibernating.&lt;br /&gt;&lt;br /&gt;The type of functionality being offered by the iPad is basically 100% of what most mobile office workers need from a computing device, my boss for example spends his entire work day in meetings and uses his PC for nothing but e-mail and documents.&lt;br /&gt;&lt;br /&gt;I think therefore that there is potential for this device, however Apple is going to have to work harder to make that obvious.&lt;br /&gt;&lt;br /&gt;Now in closing it&#39;s worth noting that the device simple had no way to live up to the hype surrounding it. It&#39;s a version 1.0 device, it has many flaws and omissions which Apple will need to address (although at the price you DO get quite a bit), So quite honestly It mightn&#39;t be bad idea to wait for version 2.0.</description><link>http://dotneverland.blogspot.com/2010/01/few-thoughts-on-ipad.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4133036378510199203.post-5348488871911667786</guid><pubDate>Wed, 16 Dec 2009 11:54:00 +0000</pubDate><atom:updated>2009-12-16T05:20:14.309-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">java scala groovy ruby clojure</category><title>No Next Big Language... Dunno, I suspect we may be stuck with one.</title><description>I&#39;ve just read Alex Miller&#39;s &lt;a href=&quot;http://tech.puredanger.com/2009/12/15/the-next-big-language-is/&quot;&gt;blog entry&lt;/a&gt; regarding the NBL (Next Big Language) or rather the fact that there will not be a NBL and that the age of multiple programming languages has arrived.&lt;br /&gt;&lt;br /&gt;I like the idea and I&#39;m all for it to take off...&lt;br /&gt;&lt;br /&gt;It&#39;s just that in my experience companies, especially those who&#39;s core industry is not IT related tend to minimize risk as much as possible, and therefore try to stay as mainstream as possible.&lt;br /&gt;&lt;br /&gt;Java after all, quickly got pushed into the mainstream by companies like IBM and Oracle throwing their weight behind it, And consequently companies adopted it - I daresay - because it presented a much lower risk than many of it&#39;s competitors at the time such as Smalltalk.&lt;br /&gt;&lt;br /&gt;Furthermore companies seem to like to standardize on a programming language since it makes things like hiring and training and administration a lot easier.&lt;br /&gt;&lt;br /&gt;Its also these companies which keep the bulk of the programming community employed.&lt;br /&gt;&lt;br /&gt;Therefore as much the acceptance of multiple programming languages is growing among us programmers I see very little acceptance of it with these companies who fork out the majority of the cash to get systems built.&lt;br /&gt;&lt;br /&gt;Consider that Microsoft talked much about multiple programming languages when it released .Net and after almost 8 years you will be hard pressed to find a lot of work being done on .Net which isn&#39;t written in C# or VB.Net.&lt;br /&gt;&lt;br /&gt;Consequently then it&#39;s normal that one of the language will get used the most and therefore employ the most people and become the NBL.&lt;br /&gt;&lt;br /&gt;Now having said that I think Sun-Acle may actually be in a good position to take the multi-language concept mainstream, more so than Microsoft in 2002. For one thing the JVM is still the most portable runtime around, furthermore it&#39;s battle tested and smokin&#39; fast. It&#39;s also widely adopted, supported and well understood.&lt;br /&gt;&lt;br /&gt;The JVM could allow a company to standardize on the infrastructure but pick the tool which will be the most productive for the development task at hand.&lt;br /&gt;&lt;br /&gt;Of course if this idea takes of, then we our next debate will be on the NBR (Next Big Runtime).</description><link>http://dotneverland.blogspot.com/2009/12/no-next-big-language-dunno-i-suspect-we.html</link><author>noreply@blogger.com (julian_za)</author><thr:total>4</thr:total></item></channel></rss>