Run a Java program from the command line
Try It! You'll Like It!
- Open a terminal window
- cd to your program project's folder if it is already written (linux command is: cd ~/private/cs400/workspace/project/ )
- If you must edit your program source code, try one of these editors
- pico (very easy to use)
pico MyProgram.java
- nino (also easy to use)
nino MyProgram.java
- emacs (many like this editor)
emacs MyProgram.java
- 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.
- 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
- 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