Monday 18 July 2011

Providing command line arguments

Here is the code of the file
public class Hello
{
public static void main(String args[])
{
if(args.length==1)
System.out.println("Hello "+args[0]);
}
}
we save it in Hello.java and compile it by javac Hello.java
Then we run it like this
java Hello Codex
and it prints out
Hello Codex
but if we want to provide multiple words as our name then we do like this
java Hello "Codex Java"
and it prints out
Hello Codex Java

No comments:

Post a Comment