Be it Firefox, a P2P client, a Java program, or whatever! Ubuntu makes it easy, but there's still some light editing to do (sorry, I don't know how to make these terminal commands yet).

For an example of how to make a Minecraft server (java app) auto-restart after crashing, see this post.

For everything else, see below:

Code via PID (Not all applications use a constant PID)
  1. Run the application
  2. Find the "ID" or PID (Process ID) in the System Monitor program (start bar > Systems > Administration)
  3. Create a document with the following code (anywhere on your machien), be sure to change the four purple pound symbols (#) to the process ID number you found.
    Code:
    #!/bin/bash
    
    while true
    do
    if [ ! `PID ####` ] ; then
    /usr/bin/autorestart1.sh
    fi
    sleep 30
    done
  4. Create another document in the install folder of the application you wish to run. Title it "autorestart1.sh" with the following code
    Code:
    cd (Path to install folder)
    Application File Name
  5. <Important> You must change the "change directory" (cd) portion to direct terminal to your application's install folder
  6. <Important> You also must change the orange "Application File Name" to the actual name of the application you wish to run.
  7. Make a link to your "Start server.sh"
  8. Copy it
  9. Go to your /usr/bin as the root user (you can use Terminal's "sudo nautilus" browser to do this with a GUI).
  10. Paste the link and rename it "autorestart1.sh" (case sensitive)
  11. You're done!



Code via Process Name
  1. Run the application
  2. Find the "Process Name" in the System Monitor program (start bar > Systems > Administration)
  3. Create a document with the following code (anywhere on your machien), be sure to change the purple "Process Name" to the process name you found.
    Code:
    #!/bin/bash
    
    while true
    do
    if [ ! `pgrep Process Name` ] ; then
    /usr/bin/autorestart1.sh
    fi
    sleep 30
    done
  4. Create another document in the install folder of the application you wish to run. Title it "autorestart1.sh" with the following code
    Code:
    cd (Path to install folder)
    Application File Name
  5. <Important> You must change the "change directory" (cd) portion to direct terminal to your application's install folder
  6. <Important> You also must change the orange "Application File Name" to the actual name of the application you wish to run.
  7. Make a link to your "Start server.sh"
  8. Copy it
  9. Go to your /usr/bin as the root user (you can use Terminal's "sudo nautilus" browser to do this with a GUI).
  10. Paste the link and rename it "autorestart1.sh" (case sensitive)
  11. You're done!
A fair warning is that the only two ways to terminate the auto-restarting of the application is through killing the autorestart sh process or restarting your machine.