Monday, 28 January 2013

Java Command Line Arguments


Java Command Line Arguments
This class demonstrates how command line arguments are passed in Java. Arguments are passed as a String array to the main method of a class. The first element (element 0) is the first argument passed not the name of the class.
Source Code
An example that prints in the command line arguments passed into the class when executed. 
public class ReadArgs
{
       public static final void main(String args[])
       {
                System.out.println("args[0] value is ["+args[0]+"]");
                
        }

Sample Run
With the following command line, the output shown is produced.

java ReadArgs zero


Output:

The following command line arguments were passed:
arg[0]: zero





<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-43075676-1', 'javaupdatebygaurav.blogspot.in');
  ga('send', 'pageview');

</script>

No comments:

Post a Comment