This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You want to know why we write (String args) in every main method?
most programs you don't just tell to "start". you tell them to start, and give them additional parameters on HOW to start. think about things like copy or cp you've probably used. you've probably done this:
copy file.a file.b
"copy" is the program, "file.a" is a parameter, and so is "file.b"
sure, the program could have been written so that you just say "copy". then it prompts you for "source file??: " and waits for you to type something in. then it says "destination??: " and waits for you to type something in...
but everybody knows you need both these arguments. so, a way was written to parse the whole line you type in, and figure the parts out. the first "word" is the program to run. the rest of the words are arguments to that program.
Java does this by taking everything AFTER the name of the program, and puts them into a string array. if i type
java myCopyProgram file.a file.b
the strings "file.a" and "file.b" are put into the array you declare in your main method. this is USUALLY named args, but you could have
public static void main (String inputs)
or really any name for it you want.
if your program doesn't need any arguments, you'll never use it. Even if you don't use it, if the user types in some stuff, it'll go in that array. HOW you use them is up to you.
does that help?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors