Java Junk             ThinkGeek

Monday, November 28, 2005

DateUtil.java

DateUtil.java has a plethora of utility methods for easily formatting and converting between java.util.Date, java.sql.Date, and java.sql.Timestamp.

NLOG4J

"NLOG4J is a production-quality log4j-replacement with native SLF4J API support."

In particular I use NLOG4J to avoid the cost associated with *not* logging. For a detailed explanation see:

2.3 What is the fastest way of (not) logging?

Loading Resources from the CLASSPATH

Here is a simple IOUtil.java that contains some useful utility methods including a few I often use for retrieving read only resources such as property and configuration files directly from the CLASSPATH. Note the following code uses SLF4J Logger interface.

Constants.java

Utilizing a single class for constants is simply a poor practice and a non robust J2EE approach to application development. In a very short amount of time, you end up with a single class comprised of constants from all areas of the application. This makes maintenance a nightmare, circumnavigates compile time checking, and allows a illegal and accidental/invalid substitutions. For example if all constants are basic types such as ints or strings then a simple fat fingering could leave you wasting cycles debugging a runtime error which could have been caught at compile time.

Those of you who may be saying; "Yeah that's right so what am I to use instead? How do I trade up my single constants class approach for an enterprise level solution?"

Well the answer,unless you are fortunate enough to be using Tiger, lies in the type safe enum pattern. Chapter fifteen of Effective Java has a complete example which is both Serializable and extensible :
Type Safe Enum Pattern

With a little customization this pattern can be augmented with a regex parse() method for resolving from string/int representations and optimized with a simple cache lookup.

Wednesday, November 23, 2005

Recompiling a Directory of LISP Files in Emacs

Use the command: byte-recompile-directory

But notice that .el files are NOT recompiled if no .elc files exist! To get around this chicken/egg issue, you can to add a 0 prefix when you invoke the command:

1) Press ESC
2) Press 0 (zero)
3) Press 0 (zero)
4) Press M-x
5) Type byte-recompile-directory
6) Press RETURN
7) Specify directory (I chose my site directory)
8) Press RETURN

Here is the actual function information ...

=== BEGIN ===

byte-recompile-directory is an interactive compiled Lisp function in
`bytecomp'.
(byte-recompile-directory DIRECTORY &optional ARG FORCE)

Recompile every `.el' file in DIRECTORY that needs recompilation.
This is if a `.elc' file exists but is older than the `.el' file.
Files in subdirectories of DIRECTORY are processed also.

If the `.elc' file does not exist, normally the `.el' file is *not*
compiled.
But a prefix argument (optional second arg) means ask user,
for each such `.el' file, whether to compile it. Prefix argument 0
means
don't ask and compile the file anyway.

A nonzero prefix argument also means ask about each subdirectory.

If the third argument FORCE is non-nil,
recompile every `.el' file that already has a `.elc' file.

=== END ===

Hello World!