Simple Basic Java Software – analysing arguments from command line

Problem

You want a simple bit of java code that takes arguments from the command line and displays them.



Solution

Good demo on how to obtain and handle java arguments.

public class Arguments {

  public static void main(String argv[]) {

    if(argv.length > 0) {

      System.out.println("args exec w " + argv.length + " args");

        for(int i=0;i...


Example


Here is a demo:

# java Arguments -a -x -y
args exec w 3 args
argv[0] = -a
argv[1] = -x
argv[2] = -y


Reference



Leave a Reply

Your email address will not be published. Required fields are marked *