CS211 Bootcamp Solutions
Step 2
Prepared by:  Alvin Law (ajl56@cornell.edu)

2.4
public class Step2
{
	public static void main(String[] args)
	{
		System.out.println("Hello, world!");
	}
}

This is a simple program that runs and outputs "Hello, world!"  Every program has a main class.  In this case, the main class is Step2.  What's unique about the main class is that it holds a function called "main," where every java program we will code begins execution.

Each main method contains one paramemter, the array of Strings called args.  These are the program's arguements.  For example, by running the following program (via command line, and of course after successful compilation):

public class Step2
{
	public static void main(String[] args)
	{
		System.out.println(args[0]);
		System.out.println(args[1]);
	}
}

with the following call:

	java Step2 "this goes in args[0]" "this in args[1]"

our output would be:

	this goes in args[0]
	this in args[1]

The two strings passed in are placed in the appropriate indices of args in order.  If no arguements are used, then args contains nothing, and cannot be indexed.

2.5
public class Step2
{
	public static void main(String[] args)
	{
		System.out.println(args[0]);
	}
}

In this program, the call:

	java Step2 Buh!

our output would be:

	Buh!