YAJB : Of course a blog about Java must start with a 4-letter acronym otherwise you can't be taken seriously. So yeah, this is yet another blog about Java. I will use it to gather together the odd bits of information that I think are usefull or interesting.

It was always possible of course to install several Java versions on the same system, but switching from one to another has always been a bit of a nuisance. In Windows I started using batch files that I wrote specifically for the purpose of setting PATH and JAVA_HOME variables while for Linux you can use the alternatives command.

But I just found out that newer Java versions actually support switching versions directly from the command line:


			java -version:1.5+ ...
		
will require that the code is run with a VM of at least version 1.5 while:

			java -version:1.6* ...
		
will use any version 1.6 VM (so it won't accept 1.5 nor 1.7, but it will accept 1.6u1). Requiring a specific version of the VM is supported but is not recommended because it would tie you to that very VM not even allowing the use of VMs that have important bug or security fixes.

Specifying a VM that can not be found on the system will result in an error of course:


			> java -version:1.4* -version
			Unable to locate JRE meeting specification "1.4*"
		

Yes, it's finally here! Welcome to the new Java era. Now let's see where this roller coaster will take us. Don't close your eyes! OpenJDK

This has already been a Java Application of the Day but I thought Bang Howdy deserves to be mentioned more. This is one of those examples that it is very much possible to write nice games using Java!

Taking a look at the latest information about that highly intriguing Java scripting language called F3 I found a reference to yet another interesting Java project I had not heard about before Flying Saucer. A strange name for a XHTML+CSS renderer but I'm not complaining, components like this are always very welcome!

Hey, I should do this more often! While writing the previous item I thought it would be nice to format the regular expression a bit by indenting it and adding some comment, this was the result:

# gobble any spaces
(\s*)
# main group
(?:
	# keyword - gather letters until first space or =
	([^=\s]*)
	# option group
	(?:
		# option 1 - attribute has no quotes
		(?:
			# gobble spaces and =
			(\s*?=\s*?)
			# value - gather anything that's not a space or quote
			([^\s"]+)
		)
		|
		# option 2 - attribute has quotes
		(?:
			# gobble spaces and =
			(\s*?=\s*?)
			# value - gather anything between two quotes
			(".*?")
		)
	)?
)
		
And while setting this up I saw that this was actually more complicated than need be so I started pruning. When I put back the resulting expression everything still worked so I must have done something right. The indented version looks like this:

# gobble any spaces
(\s*)
# keyword - gather letters until first space or =
([^=\s]*)
# optional group containing the value
(?:
	# gobble spaces and =
	(\s*?=\s*?)
	# option group
	(?:
		# value - (option 1) gather anything that's not a space or quote
		([^\s"]+)
	|
		# value - (option 2) gather anything between two quotes
		(".*?")
	)
)?
		
And the resulting expression looks like this:

(\s*)([^=\s]*)(?:(?:(\s*?=\s*?)([^\s"]+))|(?:(\s*?=\s*?)(".*?")))?
		
A bit shorter than the first version but still way too cryptic in my book.

I have been working the last couple of days on adding syntax highlighting to my blog. For this I used the jEdit syntax package that I found on SourceForge. I had to change it a bit because it was a bit too focused on using it from within an editor but all in all it is not bad.

Only the XML highlighting didn't really convince me, it would just color everything blue except for the comments. So I thought I'd take a stab at parsing the attributes so keys and values would get their own colors.

But looking at the code I realized it would take some work doing it the way they did it so I decided to just at a regular expression at right point.

Thing is, regular expressions are great but when they finally result in something like this, I have to wonder "WTF am I doing???":


(\s*)(?:([^=\s]*)(?:(?:(\s*?=\s*?)([^\s"]+))|(?:(\s*?=\s*?)(".*?")))?)
		
And this is without the escaping that is necessary when putting this in a Java string! Luckily it's only a couple of slashes but it can soon get very messy.

Oh, and what it does is figure out the attributes for an HTML or XML element. So if you have something like this:


<input type= checkbox name = "checkme" selected>
		
the regular expression will cut it up into the following tokens:
  • " "
  • "type"
  • "= "
  • "checkbox"
  • " "
  • "name"
  • " = "
  • "\"checkme\""
  • " "
  • "selected"
Of course not all of this is legal in XML, but the expression supports the most lax of the 2 formats.

Wow, for me this definitely is an historic day, Sun will release the entire Java platform as open source! And they're not just using any license, they are actually releasing it under the GPL!

But even more incredible in my opinion is Jonathan Schwartz, director of Sun Microsystems, admitting that the final push for selecting the GPL was the Microsoft-Novell anouncement last week about protecting eachother's customers from patent violations:

By admitting that one of the strongest motivations to select the GPL was the announcement made last week by Novell and Microsoft, suggesting that free and open source software wasn't safe unless a royalty was being paid. As an executive from one of those companies said, "free has to have a price."

That's nonsense.

Of course, Richard Stallman will have to revise his infamous essay "Free But Shackled - The Java Trap", but he doesn't seem to mind much, in fact he seems pretty pleased, commending Sun for taking a leadership role and saying that this makes Sun the world's biggest single contributor of open source software.

Personally I would like to see how the Linux distros will pick this up. RedHat for example has always been a big supporter of Java, spending a lot of time and effort to make sure that projects like GNU Classpath and GCJ work perfectly on their systems.

How will it all work out? Is there any use for the Classpath people to continue now that their goal of having a free implementation of the Java class libraries has been attained in one fell swoop?

And how will GCJ be integrated into all of this (because that's one project that is not going away for sure because native code compilation will always be more interesting to some people than relying on JIT compilation and the Hotspot optimizer)?

This is all so exciting! I can't wait for the future to arrive!

This is just a test to see how the code syntax high-lighting works:

/*
 * Created on Apr 22, 2005
 */
package org.codejive.common.cache;

import java.io.File;

public class FileUpdateMonitor implements UpdateMonitor {
	private File file;
	
	private long lastModified;
	
	/**
	 * Constructor
	 */
	public FileUpdateMonitor(File _file) {
		file = _file;
		lastModified = file.lastModified();
	}

	public boolean isUpdated() {
		return (file.lastModified() != lastModified);
	}

	public String toString() {
		return "FileUpdateMonitor(File=" + file + ", lastModified=" + lastModified + ")";
	}
}
		

RSS feed