Some Java utilities
 

Below are some Java programs / utilities I wrote for fun and learning.
 

1. A file/directory zipping/unzipping utility

There are numerous file and directory compression/decompression utilities for Windows and Unix platforms. Here is another one!

The binary file for this utility can be downloaded from, here.

The source code is available, here.

If you want to build the source code, it can be done simply as, javac ZipUtil.java

The utility can be run as following:

java ZipUtil [filename | dirname] <outputfile.zip> -s [d | b]    // for zipping a file or a directory (the option, "-s" specifies the compression strength. "d" signifies "default compression", and "b" signifies "best compression".)

or

java ZipUtil <inputfile.zip> -o <outdir>    // for unzipping a zip archive to a given destination folder (specified by "-o" parameter)

Notes:
1) Since this program is written in pure Java, it can be used both on Windows and Unix platforms. The utility as posted on this site, was tested on Windows platform. Few minor changes need to be done in the code (at certain places, file paths are assumed with the Windows conventions), to make it portable for Windows and Unix platforms.
2) This utility is compatible with WinZip and WinRAR software's. Any file or directory that is compressed with this utility, can be opened/decompressed with WinZip or WinRAR. Also, the ZIP archives created by other tools, can be unzipped by this utility.
3) The program is tested with JDK 1.4.x and 1.6.x.

Future directions:
1) Add GUI support

 In future, I might try to implement these enhancements.


2. Sudoku solver

The Sudoku solver can be downloaded from, here.
(The source code, as well as binaries are provided)

Instructions to use the Sudoku solver:
1) Unzip the contents of the Zip file into a folder
2) Directly run the sudoku binary as, java SudokuSolver
3) Compile the sources as, javac -classpath orbital-core.jar *.java. Now run the binary as written in step 2.
4) The puzzle is provided to the solver as a text file (board.txt).
5) The solved puzzle is printed on the console (example as following):




Notes:
1) The solver uses a logic and AI library, available from http://www.functologic.com (by, Andre Platzer). The jar file from functologic.com is provided along with the Zip package.
2) The solver is algorithmically complete. But it fails (hangs) for very hard puzzles. No attempt is made to optimize the solver for hard cases. After extensive searching on web, I found that the dancing links algorithm (suggested by, Donald Knuth) is the best method to solve Sudoku like puzzles. But I have not tried the dancing links algorithm for solving Sudoku.
3) The application is tested with JDK 1.6.0.

Ref: Andre Platzer's new site, http://symbolaris.com/
 

3. XML well-formdness checker

Some excellent XML parsers are available from reputable vendors, which can check well-formedness of XML documents. I particularly, like following utility from Xerces project: http://xerces.apache.org/xerces2-j/samples-sax.html#Counter to check for well-formedness of XML documents (although, this utility demonstrates the XML SAX API, but it can certainly be used to check for well-formedness of XML files).

But out of my interest I developed a little program which can check whether an XML document is well-formed or not.

The utility can be downloaded from, here.

The source program is available at, WellFormdness.java.

This program can be run as following:

java WellFormdness file.xml

The program produces the following output:

XML document is well formed        or

XML document is not well formed

Notes:
1) The application is tested with JDK 1.6.0
2) Following features are currently not incorporated and tested:
  a) The utility does not display error messages showing the line and column numbers.
  b) The regular expression, matching the XML names is not completely compliant as per the XML spec. But it matches the most common cases.
  c) The presence of special XML characters (like &, <, > etc.) and other entities in the data, is not taken care of.
  d) The handling of attributes is not done correctly at present. 
  e) This program does not validate XML documents against any of Schema languages. This is simply a XML well-formedness checker.

In future, I might try to implement these facilities in this utility.

This is still a work in progress, and it must not be used to check well-formedness of XML documents deployed in production.


Home


Last Updated: Dec 27, 2009