Understand Command Line Arguments in java

In this example we are going to understand the command line arguments in java. We are going to write a very simple java class with the print statement and which will take one argument.

public class CmdArgs {

    public static void main(String[] args) {

        System.out.println("My name is: " + args[0]);
    }
}


In order to compile the above java class, go to the command prompt and navigate to the directory where the java class is stored. Now, issue the command to compile the java class as:
javac CmdArgs.java

Now, to run the java class, fire the following command.
java CmdArgs Amzi

The output will be something like this:

My name is: Amzi

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
    or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete