Run a Java program from the command line

Try It! You'll Like It!

  1. Open a terminal window
  2. cd to your program project's folder if it is already written (linux command is:  cd ~/private/cs400/workspace/project/ )
  3. If you must edit your program source code, try one of these editors
    1. pico (very easy to use)
      pico MyProgram.java
    2. nino (also easy to use)
      nino MyProgram.java
    3. emacs (many like this editor)
      emacs MyProgram.java
    4. vi (or vim - my personal favorite)
      vi MyProgram.java
      You will need to learn about modes to use vi - here's a tutorial to help you get started.  Or, google vi tutorial to find many more.
  4. Java programs must be compiled and linked before they can be run.  One command compiles and links all source in the current directory.
    javac *.java
  5. Use Java to run your program with command line arguments.  This example has three command-line arguments (1 2 3).
    java MyProgram 1 2 3