Data Structures Book
On a slashdot thread I was discussing whether I should roll my own data structure or try to use one of the many, many Sun data structures.
Someone recommended this book.
Spring Framework
Researching this Spring Framework. Most interesting so far is it's touting of being modular. As in, you might only use it for a single feature and it wouldn't be bloated.
swt, eclipse and OS X problems
Following a hello world tutorial, I got stuck on this error:
java.lang.UnsatisfiedLinkError: no swt-carbon-3034
Couldn't find anything so I thought I'd post the fix for someone like me out there:
Found it from an unusual source. Seems I couldn't get the VM parameters to work so I have to do SWT's not recommended suggestion of copying the file to the jre bin path. Although they never gave the file or the path! (I'm going to send them an email.)
Just do this:
cp [path to libswt-carbon-3034.jnilib] \ /System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Libraries/
Note that libswt-carbon-3034.jnilib is version dependant. It could be named libswt-carbon "anything" .jnilib. I found in [ECLIPSE HOME] /plugins/org.eclipse.swt.carbon_3.0.0/os/macosx/ppc
Validation Action
Finished coding a validation action that parses a word followed by an array of words. For example, "ABC" would validate if "Another Bad Creation" was passed with it. This is going to be used in the ever complicated Acronym project that has been taking me forever to finish.
It's case insensitive, you can see the usage example in the 'main' class.
Mathematical constant e generator in Java
A small class to generate the mathematical constant "e". Complete with timer and digits per second clock. Unpolished. Here's a quick benchmark and you can see that it doesn't scale.

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;/**
* calculate mathmatical constant e
*/public class ECalculator {
private static final int numberOfDigits = 1000;
public static void main(String[] args) {
ECalculator myEClass = new ECalculator();
System.out.println("Calculating e to " + numberOfDigits + " digits ...\n");
Date start = new Date();
BigDecimal e = myEClass.doCalculation();
Date stop = new Date();
long elapsedSeconds = (stop.getTime()-start.getTime()) / 1000;
System.out.println("e is: \n" + e);
if (elapsedSeconds
Made useful build.xml file for use with Ant
The following build.xml file has a few targets that make compiling a project much simplier. Read on for more details.
I have the following directory structure:
(chris@hobbes)-(BackupLink)$ ls -l total 20 drwxrwxr-x 3 chris chris 4096 Apr 21 00:07 bin -rw-rw-r-- 1 chris chris 2776 Apr 21 00:15 Build.xml drwxrwxr-x 2 chris chris 4096 Apr 13 19:07 CVS drwxrwxr-x 2 chris chris 4096 Apr 20 14:32 include drwxrwxr-x 4 chris chris 4096 Apr 21 00:06 src
In Eclipse, I set the project preference to make [project root]/src the only folder on the source path. Lastly, I set bin to be the output folder. The ant script grabs any jars out of include (mostly useless to me).
When I want to create a jar, I just run the jar target. I removes the java source files before creating the jar archive. You can also increment the version number to create 'releases'. This is the best I can come up with right now.
<?xml version='1.0'?>
<project name="BackupLink" default="jar" basedir=".">
<!-- set global properties for this build -->
<property name="version" value="0.1" />
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="jarname" value="backUplink.${version}.jar"/>
<property name="docs" value="docs"/>
<property name="include" value="include"/>
<property name="lib" value="lib"/>
<property name="runclass" value="com.squarism.backUplink.BackUplink"/>
<property name="classpath" value="classes"/>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${build}/classes" />
<!-- Create the directory for the jar file -->
<mkdir dir="${lib}" />
<!-- Create the directory for the java docs -->
<mkdir dir="${docs}" />
</target>
<target name="compile" depends="init">
<!-- copy all .java files from ${src} to ${build} -->
<copy todir="${build}/">
<fileset dir="${src}" />
<!-- apply a substitution @version@ with the value of ${version} -->
<filterset>
<filter token="version" value="${version}"/>
</filterset>
</copy>
<!-- run javac to compile the source files -->
<javac srcdir="${build}" destdir="${build}">
<classpath>
<!-- use the value of the ${classpath} property in the classpath -->
<pathelement path="${classpath}"/>
<!-- include all jar files -->
<fileset dir="${include}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<delete>
<fileset dir="${build}" includes="**/*.java"></fileset>
</delete>
<!-- make a jar file -->
<jar jarfile="${lib}/${jarname}" basedir="${build}" manifest="${build}/manifest" />
</target>
<target name="run" depends="jar,docs">
<!-- run the class -->
<java classname="${runclass}">
<!-- add a command line arg: <arg value="-h"/> -->
<classpath>
<!-- use the value of the ${classpath} property in the classpath -->
<pathelement path="${classpath}"/>
<!-- include all jar files -->
<fileset dir="${include}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</java>
</target>
<target name="docs" depends="compile">
<!-- create javadocs -->
<javadoc packagenames="com.squarism.backUplink.*"
sourcepath="${build}"
defaultexcludes="yes"
destdir="${docs}"
author="true"
version="true"
use="true"
windowtitle="BackUplink API Documentation Version: ${version}">
</javadoc>
</target>
<target name="clean">
<delete dir="${build}"/>
<delete dir="${docs}"/>
<delete dir="${lib}"/>
</target>
</project>
Acronym Project – Ant and Eclipse
Having some problems getting Ant running the way I want to. It's another question of whether the IDE (Eclipse) is being too inflexible or if I'm not doing something right. Eclipse doesn't ship with functionality that allows ant build options. Here's a log of what I've been trying.
Acronym Challenge Demo
I've deployed the 1st version of the Acronym Challenge webapp to the server at this location.
Customized Ant Within Eclipse
Restarting Tomcat everytime I deployed with the Lomboz Eclipse plugin was proving to be too lengthy, so I set out trying to customize Ant a bit.