Code to the Java exec program we discussed in the context of fork: ExecTest.java. Recall that we discussed how you can use use the fork call (which creates a new process) and the exec call (which transforms the current process into a different program, like hostname in the previous example) to implement the command execution framework of Runtime.exec() in Java.
In fact, using a combination of fork and exec is how most command line shells (e.g., Bash) are implemented. See this page for a good reference on Unix system calls - in particular, I'd recommend reading the (very brief) section on fork and wait. Just following those sections is an example of implementing a simple shell program using fork, exec, and wait.