Sunday, March 15, 2015

How to Pass Java Command-Line Arguments in Netbeans IDE

Java application can accept any number of arguments from the command line. Here you will be guide how to input command line arguments  in Netbeans IDE. 

1. Simple Java code "HelloWorld.java"
package helloworld;
public class HelloWorld {    
    public static void main(String[] args) {    
        System.out.println("number of input "+args.length);      
        for (String i : args) {
            System.out.println(i);            
        }     
    }
}
 2. How to input arguments. 

  • File --> Project Properties(<file name>) 


  • Select "run"


  • Enter inputs (arguments) in Arguments text field. Separate each arguments by space and click "ok".
  • Note: If you enter argument including double quotes it takes as a single argument even-though separated by space. 
    • Ex: "go run went"  is  taken as single argument
    • Ex: go run went  <---- taken as multiple arguments.

3. Output

  • Run --> Run Main Project or press shortcut key F6.



3 comments: