<?xml version="1.0" encoding="UTF-8"?><item><title>Java 1.5</title><description>&lt;P&gt;I started reading &lt;A href="http://safari.oreilly.com/0596007388"&gt;Java 1.5 Tiger: A Developer's Notebook&lt;/A&gt; on &lt;A href="http://safari.oreilly.com"&gt;Safari&lt;/A&gt; a few days ago.&amp;nbsp; Java 1.5 is the next iteration of the Java language - it's about as radical a change to Java as C# 2.0 is, adding some of the same stuff (Generics) and some stuff that C# already has (Attributes), as well as adding some brand new stuff (like being able to override a method and change only the return type).&lt;/P&gt;&#13;
&lt;P&gt;I use to think that Java was the 'purist' language and C# was the 'pragmatist' language - I think I got that idea from the way that Java forces you to catch exceptions, while C# doesn't force you to (or even warn you that you're not catching them).&amp;nbsp; &lt;/P&gt;&#13;
&lt;P&gt;However, I recently got burned by Java when I wrote an application that, as part of it's operation, occasionally needed to send email, and when I deployed the application, I forgot to include one of the jars that the mail support needed (a .jar file is a collection of classes, similar to a .NET assembly).&amp;nbsp; Nothing warned me that I was missing a jar - so the application ran fine until it needed to send an email, at which point it would throw a ClassDefNotFound exception and restart.&amp;nbsp; &lt;/P&gt;&#13;
&lt;P&gt;Java has a much less rich standard framework than .NET does, so I've found Java programming to be a frustrating game of 'hunt the jar'.&amp;nbsp; Missing a jar upon deployment seems like it would be a common thing to do.&amp;nbsp; &lt;/P&gt;&#13;
&lt;P&gt;Anyway, Java 1.5 adds some new stuff, but the design of some of this new stuff seems inelegant.&amp;nbsp; For example, here's the C# syntax for the langauge construct that lets you iterate through the items in a collection:&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp; foreach (Item i in myCollection)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(i);&lt;/P&gt;&#13;
&lt;P&gt;Here's the Java 1.5 version:&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp; for (Item i : myCollection)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(i);&lt;/P&gt;&#13;
&lt;P&gt;The C# version is, in my opinion, a better design.&amp;nbsp; Personal preference I guess.&lt;/P&gt;&#13;
&lt;P&gt;Another thing that seems less clean is the new StringBuilder class, which is an exact copy of the StringBuffer class, but not thread safe.&amp;nbsp; If you want a faster StringBuffer, use StringBuilder - you can even search/replace the name, because the interface is identical.&amp;nbsp; But doesn't creating a new class just to change an implementation detail seem wrong?&amp;nbsp; &lt;/P&gt;&#13;
&lt;P&gt;Their new syntax for specifing sprintf style formatting is bizarre too.&amp;nbsp; It's a lot like sprintf, which is good for C programmers, but it doesn't seem to let you specify argument position other than to say 'reuse the previous position'.&amp;nbsp;&amp;nbsp; So you can say:&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp; formatter.format(&amp;#8220;%s's name is %&amp;lt;s.&amp;nbsp; He is a %s.&amp;#8221;, &amp;#8220;Woofy&amp;#8221;, &amp;#8220;Collie&amp;#8221;);&lt;/P&gt;&#13;
&lt;P&gt;The C# syntax for this would be &amp;#8220;{0}'s name is {0}&amp;#8221;.&amp;nbsp; Less C-like but much more useful because now you can do something like this:&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp; string.Format(&amp;#8220;{0}'s name is {0}.&amp;nbsp; He is a {1}.&amp;#8220;, &amp;#8220;Woofy&amp;#8221;, &amp;#8220;Collie&amp;#8221;);&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp; string.Format(&amp;#8220;My {1}'s name is {0}.&amp;#8220;, &amp;#8220;Woofy&amp;#8221;, &amp;#8220;Collie&amp;#8221;);&lt;/P&gt;&#13;
&lt;P&gt;By changing the format string you can change the position that the arguments are drawn from.&amp;nbsp; This is incredibly useful in internationalization, because in another language, the order of the arguments&amp;nbsp;will often&amp;nbsp;need to be different.&amp;nbsp; It looks like with Java 1.5 you'll need to find another way of doing string formatting if your source strings are going to be translated.&lt;/P&gt;&#13;
&lt;P&gt;The difference in the implementation between generics in Java 1.5 and C# 2.0 has been covered well &lt;A href="http://www.artima.com/intv/generics2.html"&gt;elsewhere&lt;/A&gt; so I won't do that here, but it's worth reading.&amp;nbsp; That's biased of course, since it's by Anders Hejlsberg, the designer of C#.&lt;/P&gt;&#13;
&lt;P&gt;There are plenty of other good language features in Java 1.5 - boxing and unboxing of native types for example - so it seems like a good upgrade for Java programmers, but I don't see anything that C# 2.0 doesn't already cover.&amp;nbsp; The languages are still close enough that it won't be language features that makes you choose between Java and .NET.&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description><pubDate>Thu, 01 Sep 2005 19:17:07 GMT</pubDate></item>