How do you parse commandline arguments to a Java program?
Ans : Perhaps surprisingly, commandline arguments are not encouraged, as they make a program not 100% pure Java. The reason is that some systems like MacOS don’t normally have a command line or command-line arguments. Consider using properties instead so that your programs fit more naturally into the environment. If you must use command-line arguments, have them comply with the POSIX conventions, i.e. they should • use a “-” instead of a “/” • be case sensitive, and • be concatenatable (-pst == -p-s-t). See http://java.sun.com/docs/books/tutorial/essential/attributes/_posix.html If such arguments are used, it should NOT be up to the invocating application (ie java.exe) to propperly parse them. According to the getopts routine from gnu, getopts is required to know exactly what the usable parameters are before it can properly parse them and create argc/argv. Because of that, it becomes unduly hard for calling programs such as java.exe to properly parse class arguments by themselves. Inst
[*] Perhaps surprisingly, commandline arguments are not encouraged, as they make a program not 100% pure Java. The reason is that some systems like MacOS don’t normally have a command line or command-line arguments. Consider using properties instead so that your programs fit more naturally into the environment. If you must use command-line arguments, have them comply with the POSIX conventions, i.e. they should o use a “-” instead of a “/” o be case sensitive, and o be concatenatable (-pst == -p-s-t). See http://java.sun.com/docs/books/tutorial/essential/attributes/_posix.html If such arguments are used, it should NOT be up to the invocating application (ie java.exe) to propperly parse them. According to the getopts routine from gnu, getopts is required to know exactly what the usable parameters are before it can properly parse them and create argc/argv. Because of that, it becomes unduly hard for calling programs such as java.exe to properly parse class arguments by themselves. Instea