29 May 2009

iCalendar 0.1 Grails Plugin just released

Just seconds ago I got it all ready to release the first version of the iCalender Grails plugin. Version 0.1 is absolutely simple and easy to use. It covers - in my point of view - the main topics of the iCal format.

So when should I use the iCalendar Plugin in my Grails application?
Well if you want to provide a simple iCalendar export service within your Grails controllers to first convert your event data to iCal and the send it to the client. One big advantage is that you can use a builder to describe your event data. This could look for example like this.

iCalendar.calendar {
events {
event(start: new Date(), end: new Date(),
description: 'Events description', summary: 'Short info') {
organizer(name: 'your name', email: 'your@email.com')
}
}

If you'd like to know more about this plugin please feel free to visit the plugins homepage.

Synology DS207+ - Troubles with Volume - Disk 2 crashes

From time to time my Synology DS207+ suffers from a invalid RAID1 volume and telling me "volume 1 was degrade, please repair it". Well if I do so and start the repairing process my DS207+ works for the next 24h (up 3 days). After that period it tells me that disk 2 in volume 1 has crashed and that I should replace the disk.

Well the first time I really did replace the harddisk but after 3 months the same thing happend to this brand new harddisk. So I decided to take the harddisk out and put it into my PC. Starting my OS and deleting all partions on that disc. And well - oh wonder - this worked. To me this behaviour seems like a strange bug in the Synology firmware. Anyway to me this is the fastest work around to get my NAS up and running again.

27 May 2009

SCJP - Now it gets strange

Which two about using the java.io.Serializable class are true? (Choose two.)

A) If Dog extends Animal, then Animal must implement java.io.Serializable in order to serialize an instance of Dog.
B) If Dog has-a Collar, then Collar must implement java.io.Serializable in order to serialize an instance of Dog.
C) If Dog extends Animal and Animal implements java.io.Serializable but Dog does NOT implement java.io.Serializable, you can serialize an instance of Dog.
D) When an instance of a subclass is deserialized, none of the constructors in it's constructor chain will ever be invoked.
E) If you mark a class's instance variable volatile, and then serialize an instance of that class, the state of the volatile variable will be lost during serialization.

Sun's says: Options B and C are correct. A class's superclasses don't have to implement Serializable in order to be serialized, and if a superclass doesn't implement Serializable then it's constructor will run during deserialization. A transient variable's state is lost during serialization, but a volatile variable's state is not lost.
I really do agree with option C but cannot understand why option B should be absolutely right. I still can serialize the Dog instance even if the included Collar does not implement Serializable. I could mark the Collar instance variable transient and everyone would be happy at runtime.

SCJP - This one could knock me out

Can anyone solve this? I've chosen wrong :( And probably learned something.



1. class Test4 {
2. public static void main(String [] args) {
3. boolean x = true;
4. boolean y = false;
5. short z = 42;
6.
7. if((z++ == 42) && (y = true)) z++;
8. if((x = false) || (++z == 45)) z++;
9.
10. System.out.println("z = " + z);
11. }
12. }


What is the result?

A) z = 42
B) z = 44
C) z = 45
D) z = 46
E) Compilation fails.
F) An exception is thrown at runtime.

Becoming a Sun certified Java programmer or how to become a compiler

The next two weeks I am trying to prepare myself to Sun's certified Java programmer (SCJP) exam. Up to now it really does not kick ass. Well my main troubles with the studies are currently some topics in the exam objective 3.5 (Tokenizing).

Objective 3.5 - Tokenizing with Pattern and Matcher
Let's say there's the pattern 'a?' and we would like to tokenize the following string 'aba' using the following Java class.

public static void main(String[] args) {
Pattern p = Pattern.compile("a?"); // compile the pattern
Matcher m = p.matcher("aba");

while (m.find()) {
System.out.println(m.start() + " >" + m.group() + "<");
}
}

What I expected out of this listing was something like this.
0 >a< 
2 >a< 
But what it actually returns was this.
0 >a< 
1 >< 
2 >a< 
3 >< 
Mhm. According to my study book (from which I took this example) they talking about some zero-length matches when using the greedy quantifiers '*' or '?'. They say that zero-length matches can appear under the following circumstances.
  • After the last character of source data
  • In between characters after a match has been found
  • At the beginning of source data (if the first character is not a match. Try tokenizing this string '2aba')
  • At the beginning of zero-length source data
Well this rules seems to be regular expression specific and does not have anything to do with the Java implementation. The only funny thing is - I use RegEx Buddy to develop my regexes - that I cannot reproduce it in my favourite regex editor. Yet another topic to learn by rote (means not really understanding it but memorize it for the exams purpose only)