Compiling and running java applications from android terminal?
I found an app on the play store that let me answer this question. Below are the steps I used to get javac and java running.

Install Terminal IDE

Go to the play store and install Terminal IDE, this supports everything needed to write and run java applications: vim, javac, and java.

Once the app is installed, make sure you open the app and go to Install System to install everything needed.

Compile and Run Program

Now press the Terminal IDE button to open the terminal.

Use vim to write and save your hello world program.

Then to execute it has to be compiled to a JAR file:

# javac hello.java
# dx --dex --output=hello.jar hello.class
# java -jar hello.jar hello


Pitfalls

When I first tried to compile and execute I got

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: hello.class: file not readable


This issue was fixed by compiling and running as superuser. Here's the full terminal output of my issue

terminal++@192.168.1.30:~$ javac hello.java
terminal++@192.168.1.30:~$ dx --dex --output=hello.jar hello.class

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: hello.class: file not readable
        at com.android.dx.util.FileUtils.readFile(FileUtils.java:63)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:139)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:113)
        at com.android.dx.command.dexer.Main.processOne(Main.java:247)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
        at com.android.dx.command.dexer.Main.run(Main.java:139)
        at com.android.dx.command.dexer.Main.main(Main.java:120)
        at com.android.dx.command.Main.main(Main.java:89)
        at com.spartacusrex.spartacuside.external.dx.main(dx.java:14)
        at dalvik.system.NativeStart.main(Native Method)
1 error; aborting
terminal++@192.168.1.30:~$ su
# dx --dex --output=hello.jar hello.class
# java -jar hello.jar hello
Hello world
#


More Information

Everything you could possibly want to know can be found in the Help section of the Terminal IDE app, especially in the Java sections of the Tutorial.