Our make-believe Java application for this tutorial is the common "Hello World" application. It will print the message "Hello World" on the console. The additional functionality is that we want to control the case of the message. The default will be mixed case. But we will provide a command-line argument to force the message to upper case. This argument will be --upperCase
. You will see that it takes only 1 line of extra code to implement Argument to parse the command line.
> HelloWorld < Hello World
> HelloWorld --upperCase < HELLO WORLD
public class HelloWorld { public boolean asUpperCase; static public int main (String[] args) { CmdLine.create("-t boolean -k upperCase --variable asUpperCase") .parse(this, args); if (asUpperCase) System.out.println("Hello World".toUpperCase()); else System.out.println("Hello World"); } }