Can I programmatically install a specific version of JDK (i.e. using command-line tools only) on OS X? I know you can apt-get JDK on Ubuntu. Is there anything similar on OS X? 

It looks like Oracle requires you accept a license agreement on http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html before you can download the image, so maybe not?
curl -L -b "oraclelicense=a" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-macosx-x64.dmg -O