Thursday, 17 December 2009

Java: safe character handling and URL building

This post discusses HTTP URLs in Java and how to avoid data loss due to encoding/escaping issues. Special mention is made of the query part, since it is frequently used to store data.

Thursday, 26 November 2009

Java: application to check binary class versions

scanner application screenshot

Here's a simple application based on the code from a previous post. You can run it on .class files, .jar files or directories (it'll recursively search them for .class files). It will tell you what version of Java the contained code was compiled for.


Tuesday, 17 November 2009

Java: how to use an IllegalArgumentException

Calling my web log Illegal Argument Exception seemed like a clever idea at the time. It is probably just a recipe for confusing Java neophytes searching for their program errors. I should've listened to what my granny used to tell me about clarity, precision, and terseness when choosing identifiers.

To make up for it, here's a short post about IllegalArgumentException (the exception type).

Friday, 9 October 2009

JSF: working with component identifiers (id/clientId)

This is a post about how to work with IDs in JavaServer Faces. You may find this useful if you want to use JavaScript with JSF.

Example ID developer sets on a JSF component:  foo1
What JSF might render in the resultant HTML:   j_id_jsp_115874224_691:table1:0:foo1

This is a revised version of JSF: working with component IDs (id vs clientId), though you don't need to read that. This post fixes some of the issues with the code, provides a more robust version of the library and details how to use it to make simpler, more reliable applications. The target JSF version is 1.2.

Friday, 18 September 2009

Java: character inspector application

application screenshot

This is a small application that's useful for solving character encoding bugs. If you've ever wanted to find out exactly what characters you have, or what bytes they encode to with a specific encoding, this app may do the trick.


If you want to know more about character encoding in Java, read Java: a rough guide to character encoding.


All the sources are available in a public Subversion repository.

License: MIT
Project: CharacterInspector

Saturday, 1 August 2009

JSF: a custom format panel control for localising component layout

This post describes a custom JavaServer Faces component for controlling the flow layout of controls based on localised strings.

Wednesday, 22 July 2009

Java: finding class versions

The JVM versions your Java classes will run on is often determined by how you compile them. Failure to take care with your classes and dependencies can lead to an UnsupportedClassVersionError. This post demonstrates how to check your class files.

Saturday, 18 July 2009

Java: effective Unicode

This is my attempt at a list of maxims to abide by when working with text in Java, in the vein of Effective Java or The Ten Commandments of Unicode. It is also a summary of another post on character encoding. The list is in no way comprehensive.

Thursday, 28 May 2009

Java: using XPath with namespaces and implementing NamespaceContext

XPath is a handy expression language for running queries on XML. This post is about how to use it with XML namespaces in Java (javax.xml.xpath).

Wednesday, 27 May 2009

JSF: using component IDs in a data table (h:dataTable vs clientId)

Updated 2009/11/24

This post is obsolete; go read this one instead: JSF: working with component identifiers The approach described in this post may fail if the component identifiers are not unique within the view.

Tuesday, 26 May 2009

Java: dynamically loading scripting engines (Groovy, JRuby and Jython)

Java 6 (via JSR 223) added scripting language support to the standard library. The JVM ships with the Mozilla Rhino JavaScript engine included. Where an engine is available, it is easy to add support for other JVM scripting languages. It is useful to be able to load these engines dynamically.

Tuesday, 19 May 2009

JSF: IDs and clientIds in Facelets

Updated 2009/11/24

This post is obsolete; go read this one instead: JSF: working with component identifiers The approach described in this post may fail if the component identifiers are not unique within the view.

Friday, 1 May 2009

Java: a rough guide to character encoding

It can be tricky figuring out the difference between character handling code that works and code that just appears to work because testing did not encounter cases that exposed bugs. This is a post about some of the pitfalls of character handling in Java.

Friday, 10 April 2009

Java: Unicode on the Windows command line

By default, Java encodes Strings sent to System.out in the default code page. On Windows XP, this means a lossy conversion to an "ANSI" code page. This is unfortunate, because the Windows Command Prompt (cmd.exe) can read and write Unicode characters. This post describes how to use JNA to work round this problem.

This post is a follow-up to I18N: Unicode at the Windows command prompt (C++; .Net; Java), so you might want to read that first.

Thursday, 9 April 2009

I18N: Unicode at the Windows command prompt (C++; .Net; Java)

Strange things can happen when working with characters. It is important to understand why problems occur and what can be done about them. This post is about getting Unicode to work at the Windows command prompt (cmd.exe).

Wednesday, 11 March 2009

Java: using JPDA to write a debugger

The Java Platform Debugger Architecture (JPDA) API included in the JDK lets you connect to a Java debug session and receive debug events. This code allows you to do the same things you would normally do with jdb or an IDE debugger. This is useful if you want to write your own debug, diagnostics or metrics tools.

Saturday, 21 February 2009

Java: finding the validation mechanism for an arbitrary XML document

Unfortunately, there is no 100% foolproof process for determining how to validate an arbitrary XML document. If you are receiving a document, you should not leave choosing the validation mechanism to a remote party (e.g. downloading a DTD using its document-specified URI). Doing so opens your application to, at the very least, a potential denial-of-service attack. A validation mechanism may not even be specified in the document: W3 XML Schema (XSD) does not require it; RELAX NG does not seem to support such a mechanism. Then there are some XML documents that just don't have a schema of any form.

Nevertheless, there are times when you need to inspect a document to find out what it is. Most commonly, support is required for multiple versions of a document, where the structure and validation mechanisms change over time.

Note: when talking about validation, this post is not referring to whether the XML is well formed or not. Any XML parser should be able to check the syntax. This is about external constraints imposed on the document structure via a schema, DTD, etc.

Monday, 16 February 2009

JSF: working with component IDs (id vs clientId)

Updated 2009/10/17

WARNING: this post is obsolete; go read this one instead.

Tuesday, 3 February 2009

I18N: a non-technical software bug

Can you spot the problem with the following dialog?

Installation dialog with flag icons asking user to pick a language. Retrieved Feb 2009.

I expect the developers of the Steam installer are making trade-offs for the benefit of younger users - providing visuals to help match them with their language. However, using flags in software products is generally a bad idea.