Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

April 30, 2015 Categories: Core Java Basics. No Comments on Command Line Arguments

In this article we will learn about what a command line argument is and how to access and work with the command line arguments in Java.

 

Sometimes we might want to pass extra information while running a Java program. This extra information passed along with the program name are known as command line arguments. These command line arguments are separated by white spaces.

 

Command line arguments can be accessed using the string array specified in the main function’s signature. For example, if the array name is args, then the first command line argument can be accessed as args[0] and the second command line argument can be accessed as args[1] and so on.

 

Let’s look at the following Java program which access two command line arguments, adds them and displays the result to the user:

 

 

Command line arguments are specified as shown in the below screenshot:

 

command-line-arguments

 

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

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

Scroll Up
Thank you for visiting startertutorials.com! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: stuts.me