Saturday, 16 March 2013

Good Old java.io.RandomAccessFile

An old friend from JDK 1.0 days. The overloaded write operation will write byte arrays, ints etc. to the file from the position of the current file pointer. The length() method returns the length of the file in bytes.

Wednesday, 16 January 2013

Department of Homeland Security Says No to Web Java (Java 7, That is)

The DHS recommends users disable Java in their web browsers. Oracle has issued some security fixes.

Wednesday, 26 December 2012

Hadoop, the MapReduce Paradigm and the Corresponding Mindset Change

The latest rage in the Java universe is Hadoop, a platform for "Big Data" processing. A skew of O'Reilly books have been published on the subject. It implements the MapReduce paradigm popularized by Google.

MapReduce is something inspired by LISP. A Map takes a function and a list of arguments and applies the function to each one of the arguments. A Reduce operation combines data points into one value using a binary operation.

So a "MapReduce" operation consists of 1) applying a function to a list, to generate a new list, 2) combine the elements of the list, using some binary operator (which could be simple addition, or something more complex, like XOR) to produce a single value.  Many algorithms can be expressed using this paradigm.

You can see how this can speedup parallelisable tasks. E.g. A word count on a huge file can be mapped onto different machines and results collated via Reduce.

It is a simple divide and conquer model for processing data in a parallel fashion.

It is the model used by Google to achieve massively parallel processing.

This type of computing, though, requires an altogether different mindset. Whereas previously we were designing programs for single machines, or rather single processor machines, we now need to create algorithms that work in the multiprocessor/multimachine context - parallel algorithms.

Saturday, 14 July 2012

The Art of Backporting: Using Java 5 features in Java 1.4

Backporting is the application of a patch or fix to a version of an application software which precedes that for which the patch was designed. One example would be the use of Java 1.5 features in Java 1.4. Basically your 1.5 code is used to generate bytecode that is compatible with a 1.4 VM.

Take for example generics which allows us to define objects with types as parameters, such as  List of Strings. Due to Java's implementation of generics using type erasure - whereby type information is in fact wiped out in the compilation phase - it is fairly easy to generate Java 1.4 compatible bytecode from 1.5 generics-based code. Victory to backporting!

Saturday, 16 June 2012

Adding External Jars (aka "Archives") to an Eclipse Project

Suppose you need to include some external libraries in your Java build path. Right click the project, click on Build Path and then "Add External Archives". Presumably you've created a directory in your project folder that holds all these external JARs.

Awesome IO with Apache Commons

Awesome IO with Apache commons starts with org.apache.commons.io. Among the most useful aspects of this package are the static utility methods provided by IOUtils.

Friday, 15 June 2012

Hacking apache codecs

Apache commons codec was developed initially to provide a definitive implementation of a Base64 (binary data in ASCII) encoder in Java. Base64 is used in MIME attachments.