Wednesday 28 January 2009

Attaining Ultimate Mastery of the Java Alphabet Soup

Java anagrams:

  • MMAPI - Mobile Media API. Audio/video API for resource-constrained devices.
  • Java WSDP (Wiz-dip)- Web Services Developer Pack
  • JAX-RPC - Java API for XML web services (part of Glassfish, open source application server). Glassfish versus JBoss is discussed here.
  • UTF-8 (UCS/Unicode Transformation Format) - preferred encoding for web. Backwards compatible with ASCII - hence popularity. Backwards compatibility is a great feature in computing. It allows one installed base to immediately transfer to a new installed base. Think C/C++. Java 6 Update 11 had a new UTF-8 charset implementation.
  • UCS - Universal Character Set. abstract charset on which many charsets are based.
  • JCP - Java Community Process
  • JSR - Java Specification Request

Acronyms for Java debugging architecture:

  • JDWP - Java Debug Wire Protocol
  • JDI - Java Debug Interface
  • JVMTI - Java VM Tool interface

Saturday 24 January 2009

Getting Groovy with SwingWorker TV

javax.swing.SwingWorker is the generic type for SwingWorker, which came in Java 1.6. Various incarnations of the SwingWorker existed prior to 1.6 though. T is the result type returned by various methods, and V is the type used for carrying out various intermediate results. The class implements the RunnableFuture interface.

The primary purpose of a SwingWorker is to do lengthy GUI-interacting tasks in a dedicated thread. Subclasses of SwingWorker must implement the doInBackground() method to perform background computation.

The concept of a Future<V> is an asynchronous computation. Methods exist to check if the computation is complete, to wait for completion and retrieve the result of the computation.

A FutureTask<V> is a cancellable asynchronous computation. This class also implements the RunnableFuture interface.

Thursday 22 January 2009

ClassLoaders 'R Us

The class ClassLoader is an abstract class. Given the NAME of a class, a class loader should attempt to LOCATE or GENERATE data that constitutes the definition of a class.

For more information, consult the JLS.

Saturday 17 January 2009

Castor

To quote castor.org, Castor is an "Open Source data binding framework for Java[tm]", the "shortest path between Java objects, XML documents and relational tables". We have Java-to-XML binding, Java-to-SQL persistence and more. Looked at in reverse, you can think of it as a Java persistence layer. It was developed by some guys at Intalio, Inc. Castor uses JUnit to build and test components.

Sunday 11 January 2009

Spring Framework and Aspect-Oriented Programming

IntelliJ has full support for the Spring framework which supports Aspect-Oriented Programing
(AOP).

AspectJ is another AOP framework.

The idea of AOP is an application or service has various "aspects" such as logging, perfomance monitoring, exception handling etc.

Dependency injection and AOP are complementary techniques.

IBM have a series of articles called AOPAtWork. Here is a sample article: "Say goodbye to scattered and tangled monitoring code, as Ron Bodkin shows you how to combine AspectJ and JMX for a flexible, modular approach to performance monitoring".

Thursday 8 January 2009

Java Debugging - The Java Debug Wire Protocol

The JDWP (JD WordPerfect or "Java Debug Wire Protocol") is the protocol a debugger uses to communicate with a JVM (which may be on a different machine). It's one layer within the JPDA. It's worth knowing the basic architecture of the JPDA.

the joys of java.util.concurrent

Since java ONE-FIVE we have had the java.util.concurrent package, which introduced the remarkable BlockingQueue interface (which extends java.util.Queue). The "B&Q" interface has a wide range of implementations:
  • ArrayBlockingQueue
  • DelayQueue
  • LinkedBlockingQueue (a bq based on linked nodes)
  • PriorityBlockingQueue
  • SynchronousQueue

An ArrayBlockingQueue is a BOUNDED blocking queue backed by an array. It orders elements using FIFO discipline. This is the classic "bounded buffer" in which a fixed-size array holds elements inserted by producers and extracted by consumers. The head of the queue is the element that has been on the queue the longest time.

These data structures are all part of the wonderful Java Collections Framework. Enjoy the benefits of enhanced-for loop, generics and auto-boxing.

Here's a precanned example of enhanced-for-loop in action, utilising the colon operator:

void cancelAll(Collection c) { for (TimerTask t : c) t.cancel();}

Wednesday 7 January 2009

Java Mobile Madness!

Nokia Series 40 Java SDK (50MB download), JavaME SDK,  EclipseME (install Eclipse then use the built-in updater), Antenna (Ant for wireless Java projects). It was created by the MTJ project team.

When you first run EclipseME you will need to create (at least one) Device Definition.