Running java from the command line:
[Windows]
- Go to the start menu, and select the "Run..." option
- type "cmd" and press enter
a command window should pop up
[(Li|U)nix]
- Open up a terminal window.
- [optional] To see more about what kinds of options you can set when running java from the command line, type "java" and press enter.
- navigate to the directory with the java files.
if you are on the cec machines, go to the h:
- if the java file that has the main(String[] args) method is in a package, you should be in the directory below the directory of that package name. (e.g. if your file is in the machine package, it should be in directory named "machine" and you should be in the directory below that)
- then type at the prompt: "java Foo" where Foo is the name of the class (don't include the .class part). For packaged classes, use "java pkgName/Foo" where pkgName is the package directory name.
Note: Putting words after the "java Foo" command will pass those arguments to the main methods. This is where the variables in the (String[ ] args) come from. This holds for executing a .jar file as well.
- to run a .jar file, do the same steps as above (note, .jar files are no in a package, so you should be in the same directory), and then call "java -jar Foo.jar" where Foo is the name of your .jar file.