I designed and implemented a dual-API SDK at my current job. This dual-API SDK did not initially run on any application server.

During this implementation, I learnt that it is best to use a dynamic language like JRuby or JPython or Groovy for demonstrating & learning the capabilities of the API as well as interactively test some edge-case scenarios that are not so easy to automate (randomly causing network outages, database outages, etc.). This was very useful especially at the Sprint reviews to demonstrate the new functionality.

It is incredibly easy it is to set up some complex scenarios interactively using the Java API calls in one of the above 3 dynamic languages. We are still using JDK 5 and so could not take advantage of the built-in scripting support in JDK 6.

We chose to use JRuby (due to the familiarity of Ruby to some developers) even though my favorite was JPython, especially because I have had experience building a large-scale enterprise system using Python in one of my previous jobs at a startup.

However, we ran in to one big problem: The APIs (API interfaces) that use Java Generics were impossible to test using JRuby. We kept the usage of generics to very minimal in our client API interfaces but for obvious reasons our SPI-side interfaces used generics heavily.

After a while, I also realized that it is impossible to type all of the JIRB commands correctly. Any typos in JIRB can lead to really ugly stack traces on the console. Hence, the need for tab-completion and file-based history to remember all of the commands that can be accessed by using the up-arrow/down-arrow keys.

Also, as a nice touch to our Sprint review demos, we customized the command prompt to display our product name (I have changed that to “MYSDK”, below). So, the following .irbrc file was created and copied to the user.home dir.


# ~/.irbrc
# enables Tab completion
require 'irb/completion'

#IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:USE_READLINE] = true
IRB.conf[:ECHO] = false
IRB.conf[:IRB_NAME] = “MYSDK”
IRB.conf[:DEBUG_LEVEL] = 0
IRB.conf[:AUTO_INDENT_MODE] = true

# Setup a file-based history across sessions of irb
require ‘irb/ext/save-history’
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = “#{ENV['IRBRC']}-history”

require ‘java’
import java.lang.System

# SDK stuff
# My SDK imports go here..

Technorati Tags: , , , , ,

One Response to “Best way to demo/learn a Java-based API”

  1. AlexAxe Says:

    Hello,
    Can i get a one small picture from your blog?

    Have a nice day
    AlexAxe

Leave a Reply

TOP