Command Line Arguments in NetBeans IDE


Problem of a student:
I need to pass the command line arguments to my java program, 
I'm using netbeans IDE, anyone please let me know how to pass comand line arguments to our program(to main method) in netbeans. 
Solution:
We will create a new Java Application project and will add some code to the Main method which will print the provided command line arguments on the console.

Steps:


1.       File -> New Project

2.       Create a New Class with main method like below

3.       Open project properties (by right click on project name)

4.       Select run from categories

5.       Specify Main class and arguments, like below

 
 



6. Finally run project
 
package nk;
/**
 *
 * @author Navindra Jha
 */
public class User {
    public static void main(String args[]) {
        String uname=args[0];
        String upass=args[1];
        if((uname.equals("navindra"))&&(upass.equals("jha"))){
            System.out.println("you are authorized user");
        }else{
            System.out.println("Sorry, you are unauthorized user");
        }
    }
}
 

No comments:

Post a Comment