Working with command line arguments in Java

This post is to demonstrate the use of Command Line Arguments

Consider a program

public class  CommandLineDemo
public static void main(String[] args) 
String name=args[0];
System.out.println("Hello "+name);


Now in the given program, the line in red requires the value which will come as a command line argument.

Hence to accept that value, there is a small change in run command.

Compilation is same : javac CommandLineDemo.java

Run: java CommandLineDemo Tom

after writing file name there will be a space followed by the argument.

Still not clear watch the video


Post a Comment