Software Development

A useful introduction to JavaScript video lecture

I came across the following video ("The JavaScript Programming Language") that is a lecture by Douglas Crockford (who is a "JavaScript Architect" at Yahoo!) in which he discusses JavaScript. It is split into four 30-minute parts (totaling 2 hours):

It's useful to download the slides because the video doesn't always show them when he is referring to them.

It is a good introduction to JavaScript, explaining how parts of the language works as well as offering advice on how to use (or not use) various features of it. He also talks some about the history of the language.

Getting Postgresql running on Ubuntu and OS X (Leopard)

Here are some good articles on how to get going with Postgresql on Ubuntu:

http://help.ubuntu.com/community/PostgreSQL

And Mac OS X 10.5 (Leopard):

http://www.z1r0.com/2008/03/configuring_postgresql_82_in_o.html

Note that version numbers don't matter, as I was able to apply these instructions to Postgres 8.3.

I also find the pgadmin3 tool to be very helpful with Postgres. In Ubuntu you can find it in the repositories, in Mac OS X, you can get a binary to install from here.

Difference between Java Generics and C# Generics

As you may already know, Java's generics are just compile-time checking and are not implemented in the JVM, whereas C#'s generics have type-checking implemented in both the compiler and the CLR and is more strongly-typed. However, Java's looser implementation allows the following, whereas C#'s does not:

Lets say we have a generic interface:

public interface GenericInterface<T> {
    public int getSize(T t);
}

And we have interfaces that extend this interface:

public interface StringInterface extends GenericInterface<String> {
}

Getting the current method name in Java 1.5

Example of how to write functions that return the name of the calling method (only works in Java 1.5):

	public static String getCallingMethod() {
		return trace(Thread.currentThread().getStackTrace(), 2);
	}

	public static String getCallingMethod(int level) {
		return trace(Thread.currentThread().getStackTrace(), 2 + level);
	}
	
	private static String trace(StackTraceElement e[], int level) {
		if(e != null && e.length >= level) {
			StackTraceElement s = e[level];
			if(s != null) {
				return s.getMethodName();
			}
		}
		return null;
	}

JUnit test for this (assuming the methods above were written in a class called StackUtil):

Spring configuration in Java code

A common complaint with the Spring Framework is that doing configuration in XML is problematic. You don't know at compile-time if your configuration is valid and it doesn't work with existing Java refactoring tools.

Now you can use annotation-based Java code for configuration. It is in development but looks promising. Read about it at Rod Johnson's blog or a blog at Spring-Loaded. Download a copy of it here.

Java/.Net 2.0 web service interop with XFire

In this entry I discuss reasons to switch from Axis to XFire, and then how to get XFire as a server working nicely with .Net as a client.

I have written some past entries about Java/.Net web service interop, specifically how to get a Java Axis server working with a .Net 1.1 client. Now with .Net 2.0 we have nullable types built in to the language which removes the need to use the 3rd party library NullableTypes to handle nullable values.

Hibernate DAO using Java 5 Generics

For one of my projects, I have used Java 5 Generics to simplify creation of Hibernate DAO's. I no longer have to duplicate the typical CRUD operations in every DAO class. Note that I am using Spring's HibernateDaoSupport. If you want to see an example of a non-Spring generic DAO, the authors of Hibernate have posted one on their blog. Though mine may not be the best practices for Hibernate, I thought I'd post it just to show an example of what can be done with Java 5 generics and how much code can be reduced with it.

Migrating a web project from MyEclipse to Web Tools Project (WTP) 0.7

I recently migrated a web project that was using MyEclipse to using Eclipse WTP. It was actually quite simple. This assumes you have Eclipse 3.1 and WTP 0.7 installed (WTP also requires EMF and GEF to be installed). I started by creating a web project using WTP's template (create a new "Dynamic Web Project"). Then I inspected the files it created and applied the differences to my existing MyEclipse-based project.

"Open Implementation" plugin for Eclipse

I came across an Eclipse plugin that adds an "Open Implementation" option so you can right-click on declarations/instances/method calls of interfaces and open an implementation for it (if there's only one, it goes straight to it, if there is more than one gives you a choice first). You can also assign a hotkey to it (defaults to ALT-F3).

Getting JDK 1.5 and Tomcat 5.5 up and running in Debian Linux

I know I wrote an entry before with some links to how to do this before, but I just recently went through the process again and wanted to write down the specific steps.

First to install Java 5, go to the Sun download page, select JDK, and get the non-RPM installer for Linux.
Syndicate content