• The group of strings what we are passing as an argument to the main method from the console or command line are known as command line arguments.
  • Every command line argument would be accepted by the JVM in the form of a String object.
  • JVM will always executes main method by passing object of an array of strings.
  • JVM would never execute main method by passing null
  • JVM always executes main as a thread. 

 

Program on command line arguments:

package com.instanceofjavaforus;

public class CommandLineArguents {

    public static void main(String args[]){
      
        System.out.println("Your first argument is: "+args[0]);
    }
  
}

  • >javac CommandLineArguent.java

    >java CommandLineArguents

    OutPut:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at com.instanceofjavaforus.CommandLineArguents.main(CommandLineArguents.java:8)
  • >javac CommandLineArguent.java

    >java CommandLineArguents  instance

    OutPut:
    instance

Instance Of Java

We are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu