Sunday, 2 March 2014

Command Line Parameters in Java (2)

If you need to include space(s) in a command line parameter, the whole parameter must be enclosed by quotes as shown below:

andrew@UBUNTU:~/Java$ cat prog35.java
public class prog35
{
public static void main(String[] args)
  {
  System.out.println("Hello " + args[0]);
  }
}
andrew@UBUNTU:~/Java$ javac prog35.java
andrew@UBUNTU:~/Java$ java prog35 "Andrew Reid"
Hello Andrew Reid
andrew@UBUNTU:~/Java$