For points, present your app or running Java program to the TA or CA. Be sure they have typed your netid correctly.
You will be using shell commands (similar to the C++ Bonus example) to navigate inside your directory.
mkdir java1 cd java1
The rest of this example assumes you are in the 'java1' directory (use 'pwd' to print your current working directory). Create a new program "Hello.java" inside this directory using gedit or another editor. For example:
public class Hello { public static void main(String[] args) { System.out.println("Hello World! You gave me "+ args.length+ " arguments"); // Todo write a loop to print the contents of the args String array } }
To list the contents of a file, use less or cat:
less Hello.java
cat Hello.java
Note that capitalization must match. That is, if the class is called "Hello", then the file must be "Hello.java". To compile your class, use javac. For example:
javac Hello.java
To compile all files in your current directory:
javac *.java
To run your Hello program use "java" to start the Java virtual machine:
java Hello
java Hello Bonjour World
Now, copy Zen.java into this directory. For example:
cp ../workspace/Challenge2-Hollywood/Zen.java .
By the way, cp is the file copy command ".." means previous directory and "." means current directory.
Challenge: Create a program "add" that takes two integers on the command line and adds them together. For example, the following program should print 5:
javac Add.java
java Add 2 3