Classnotes | JAVA01 | RecentChanges | Preferences No diff available--this is the first major revision.
(no other diffs)In the original example, you'll recall we had a 'String' declaration next to the 'main' function. This was no ordinary string, it was declared as an array (or an array of strings). (We will examine arrays in more detail later on)
class Hello {
public static void main(String[] arguments) {
// My first Java program goes here
}
}
As we shall see later, this is the way to pass arguments to a function. Since this is our main function, the arguments that are passed to the function come from the command line.
For example, if we ran our program thusly:
C:\> java Hello foo bar -k
then our String would have the values:
"Hello" for the first value
"foo" for the second value
"bar" for the third value
"-k" for the fourth value
The way to reference these strings is to use the square brackets "[ ]" with a number inside of them. So, for the above example, arguments would be set to these: